arcpy.da.Describe on Group Layer causes hard crash on ArcGIS Pro 3

675
9
03-14-2023 12:52 AM
AndyEgleton
New Contributor II

Hi,

I've encountered an issue in ArcGIS Pro 3, when using arcpy.da.Describe on layers (.lyr/.lyrx) that contain a group layers, it causes a hard crash in ArcGIS Pro 3.

If running the same script outside of Pro the script will just terminate. I can't catch the error with try/except either.

No issues with layer files containing a single layer.

The issue doesn't occur using arcpy.Describe, but that's not as useful as a dictionary. I've modified my code to handle things differently for layers and maps, but thought it worth reporting this error.

 

import arcpy

lyr = r"c:\temp\group_layer.lyrx"

desc = arcpy.Describe( lyr )
desc.dataElement.name
>>> group_layer.lyrx

# Hard crash here...
desc = arcpy.da.Describe( lyr )

 

 

Tags (3)
0 Kudos
9 Replies
DanPatterson
MVP Esteemed Contributor

Does this crash too?

from arcpy.da import Describe

dir(Describe)
['__call__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', 
 '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__',
 '__init_subclass__', '__le__', '__lt__', '__module__', '__name__', '__ne__',
 '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__',
 '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__',
 '__text_signature__']

... sort of retired...
0 Kudos
AndyEgleton
New Contributor II

Hi Dan,

That works as expected, sorry forgot to type the last bit of code in my example, its when trying to describe a group layer I get a hard crash:

arcpy.da.Describe( group_lyr )

 

0 Kudos
DanPatterson
MVP Esteemed Contributor

I don't have any lyrx files to test, but if it does the same thing on another one, (or no one else weights in), you should forward this as a bug


... sort of retired...
0 Kudos
by Anonymous User
Not applicable

I gave it a try on a layer group and it stalled at the da.Describe() and failed silently as well.  I'd report it as a bug.

import arcpy

try:
    lyr = r"C:\Users\klingj\Documents\ArcGIS\Projects\Testing\Group Schools.lyrx"

    desc = arcpy.da.Describe(lyr, 'layer')
    for k, v in desc.items():
        print(f"{k}: {v}")
except Exception as ex:
    print(ex)

 

The lyrx file is just a file with a dictionary in it though. Open it up in notepad or vs code.  You could load it in using json and parse out the information:

import json
import arcpy

try:

    glyr = r"C:\Users\u\Documents\ArcGIS\Projects\Testing\Group Schools.lyrx"

    with open(glyr) as jFile:
        lyrD = [l.replace('\n', '').strip() for l in jFile.readlines()]  # <- strip the \n to format as valid json
        strlyr = ''.join(lyrD)  # <- form a single string

        gLyrJson = json.loads(strlyr)  # <- load as json

    for lyr in gLyrJson['layerDefinitions']:
        print(lyr['name'])
        print(lyr['featureTable']['dataConnection'])

        # Try describe here!
        # you'll have to create the path so this might be in the dictionary, I had to parse out the DATABASE=. for this example
        path = fr"C:\Users\u\Documents\ArcGIS\Projects\Testing{lyr['featureTable']['dataConnection']['workspaceConnectionString'].replace(r'DATABASE=.', '')}\{lyr['featureTable']['dataConnection']['dataset']}"

        desc = arcpy.da.Describe(path)

        for k, v in desc.items():
            print(f"{k}: {v}")

except Exception as ex:
    print(ex)

 

0 Kudos
DuncanHornby
MVP Notable Contributor

I see you are using arcpy.da.Describe which having read the Help file I've discovered that you use this if you want results in a dictionary format.  I've never ever used that approach and I wonder if you don't need your description as a dictionary object then maybe you can use arcpy.Describe() instead?  This is the approach I use and have never had any issues with.  If it is a bug as hinted by other responders, then if you need to resolve this quickly, I would suggest you explore the use of arcpy.Describe().

0 Kudos
AndyEgleton
New Contributor II

I've used arcpy.Describe for LayerFiles now, its just extra lines of code:

desc = arcpy.da.Describe( item )
some_detail = desc.get( "shapeType", None )

vs

desc = arcpy.Describe( item )
some_detail = None
with contextlib.suppress( AttributeError )
    some_detail = desc.shapeType

I'll raise a bug.

ShaunWalbridge
Esri Regular Contributor

Did you have a chance to log this? We can make sure it gets looked at once it is.

Thanks! Shaun

0 Kudos
AndyEgleton
New Contributor II

Hi Shaun,

There is an open case: 03301233.

Thanks

0 Kudos
ShaunWalbridge
Esri Regular Contributor

Thanks Andy. I can't see it till it can wend its way into a bug report, but will keep an eye for it.

0 Kudos