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

428
0
12-16-2022 11:34 AM
Labels (1)
MollyMoore
Occasional Contributor

I use a tool within a custom Python toolbox to set definition queries on multiple layers that have similar schemas that I need to filter for additional processing. Here is the execute() part of the code for the tool:

def execute(self, params, messages):
# define parameters
eoid = params[0].valueAsText
specid = params[1].valueAsText

aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps("Map")[0]
for lyr in m.listLayers("eo_*"):
lyr.definitionQuery = "EO_ID = {}".format(eoid)
for lyr in m.listLayers("CPP *"):
lyr.definitionQuery = "EO_ID = {} OR EO_ID IS NULL".format(eoid)
for lyr in m.listLayers("spec filter *"):
lyr.definitionQuery = "SpecID LIKE '{}%'".format(specid)

I've been using this tool for years with no issues. Lately, the tool has been failing with the following error code:

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

It will apply the definition query on some of the layers, but not others and seems inconsistent for which layers the definition query is applied. Here's a screen clip of the layers in my Pro project:

MollyMoore_0-1671219083717.png

Anyone have any ideas for why this is happening, but didn't seem to be an issue in the past?

This looks related to the issue here: https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/td... but these layers do support definition queries (either manually or in the past when it worked through Python).

The layers are from feature services. I'm currently using Pro 2.9.5 and also tested in 2.9.0. We are currently dealing with another bug that is prohibiting us from upgrading to 3.0. 

0 Kudos
0 Replies