ArcGIS Pro: layer.supports...the check works, then fails when trying to read that same property!??!?

09-07-2021 10:08 PM
Occasional Contributor

for lyr in updateMap.listLayers():
     if lyr.supports("DATASOURCE"):

A script opens an ArcGIS Pro project file, goes through the list of layers within a map, checks to see if each layer supports the 'DataSource' property before giving me a message with that datasource

The script fails as it reaches a layer which doesn't support the 'DataSource' property....

NameError: The attribute 'dataSource' is not supported on this instance of Layer.

Can someone explain this non-sensical behaviour to me?

ArcGIS Pro 2.8.2

Tags (3)
0 Kudos
3 Replies
MVP Regular Contributor

I have no idea why this happens, but to not let it fail your script, you can do it in a try-catch block:

for lyr in updateMap.listLayers():
    except NameError:

Have a great day!
MVP Esteemed Contributor

from Layer—ArcGIS Pro | Documentation

could it be your layer source?

(Read Only)

Returns the complete path for the layer's data source. It includes the full workspace path and name of the dataset. For enterprise geodatabase layers, a string containing the layer's connection information is returned.


Enterprise geodatabase layers in an ArcGIS Pro project do not retain the path to the database connection file (.sde) that was used to create the layer.



... sort of retired...
0 Kudos
Occasional Contributor

Possible (and I'll check) but not likely as all the layers that I check (using a query on the list layers) are in the same location (default.gdb)...but even then, the whole point of 'supports' is that this type of error doesn't occur.

0 Kudos