Python script crashing for a layer file

1650
6
07-27-2016 07:48 PM
BillAnderson1
New Contributor

I have a python script which walks through directories looking for layer files, in order to compile a list of layer files into a csv file. It crashes ArcGIS 10.4 (and also crashes Python when run via the command line) on accessing a particular layer file which retrieves data from an SQL table.

The problem in the layer file appears to be caused by the definition query in the layer file: when the layer has no definition query then the script is fine; when the layer has a definition query which returns no data then the script is also fine; however when the layer has a definition query which does return data then the script crashes. Other layer files exist which have the same definition query, but the script doesn't crash when accessing those other layers.

Recreating the layer from scratch hasn't worked. Has anyone run across a similar problem before?

Tags (4)
0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus

I see nothing that should be an issue unless there is no OBJECTID field Displaying a subset of features in a layer—Help | ArcGIS for Desktop

why not through the test within a try except block, trap the error if possible, and continue on past that one file until you can identify the source of issue

0 Kudos
BillAnderson1
New Contributor

Hi Dan. I should have included the script as an attachment to the original query. There is a try except block, and it is catching some errors, but even with the error trapping python is still crashing. I've narrowed down the problem further to this line: lyrExtent = lyr.getExtent() which is supposed to extract extents from the layer file. With that line commented out there are no errors and no crashes. With that line active most layers are ok, but some layers are generating errors which are caught by the error trapping, and there is one layer file which completely crashes python and ArcGIS, but only when that layer has a definition query which returns data.

I'm new to python scripting and arcpy, so maybe the way that my script is extracting extents is completely wrong. I've also attached a sample of the file being output by the script, currently the extents in the file are all dummy values.

0 Kudos
NeilAyres
MVP Alum

And, if you load that layer into a new ArcMap session? What do you see? Extent, coord sys etc etc

BillAnderson1
New Contributor

Hi Neil, as far as I can tell it's exactly the same as every other layer that I have. It's starting to look as though there is a bug in the arcpy libraries as the script is fine when the layer has no definition query added, the fatal crashes only occur when a definition query is added which returns data. The layer in question displays in ArcGIS with no problems (and the source data displays in QGIS with no problems)

Screenshot of problem layer properties:

Screenshot of properties of layer with no problem:

0 Kudos
NeilAyres
MVP Alum

Because this works with other layers with the same definition query, I still suspect there maybe something funny with the underlying data. Is there something invisible way outside the domain or something strange like that? Null Geometries?

0 Kudos
BillAnderson1
New Contributor

I've checked through it, all of the underlying data is fine. There has to be something odd going on though: I did a little further troubleshooting, and there is no crash when the definition query returns just one record. When the definition query returns multiple records, then there is a crash. All of the records have the same SRID, they are all points, etc etc etc. I've been affected before by bugs in the ArcGIS software on previous occasions, this may be another bug.

0 Kudos