Querying a specific FeatureLayer in a FeatureLayerCollection returns code 500 'Error performing query operation'
Describe the bug
Iterating though FeatureLayers in a FeatureLayerCollection to query() each for a FeatureSet. One FeatureLayer raises a data error exception. Other FeatureLayers (60 total) perform as expected. The endpoint of the Feature Layer with the issue is:
https://roads.udot.utah.gov/server/rest/services/LrsEnabled/Read_Only_LRS_Network_Service/FeatureServer/22
To Reproduce Steps to reproduce the behavior:
from arcgis.features import FeatureLayerCollection
fs_url = "https://roads.udot.utah.gov/server/rest/services/LrsEnabled/Read_Only_LRS_Network_Service/FeatureServer"
featlyrs = FeatureLayerCollection(fs_url)
featlyr = featlyrs.layers[22]
featset = featlyr.query(where="1=1")
print(len(featset), "features")
error:
Traceback (most recent call last):
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\layer.py", line 3565, in _query
result = self._con.post(
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1528, in post
return self._handle_response(
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 990, in _handle_response
raise Exception(data["error"])
Exception: {'code': 500, 'message': 'Error performing query operation', 'details': []}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\justinpjohnson\Projects\UDOT\LayerList-DataChecks\test.py", line 9, in <module>
print(len(featset), "features\n")
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\layer.py", line 2350, in query
records = self._query(url, params, raw=as_raw)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\layer.py", line 3574, in _query
if queryException.args[0].lower().find("invalid token") > -1:
AttributeError: 'dict' object has no attribute 'lower'
Screenshots If applicable, add screenshots to help explain your problem.
Expected behavior With all other FeatureLayers in the Collection, the code above will print the total number of features. The 'Error performing query operation' is encountered on layer 22 only. Using the query form in the REST Services Directory appears to perform as expected on this layer.
Platform (please complete the following information):
- OS: Windows 11 Pro version 21H2
- Browser: Chrome
- Python API Version: 2.1.0.2
Additional context Add any other context about the problem here, attachments etc.
@authalic We cannot access this layer. Is it possible to make it public? Otherwise you will have to go to support with the issue
@nanaeaubry
Sorry about that. I didn't realize it was restricted. I'm meeting with coworkers later today and I'll see if we can open it up to public access. I'll also submit a support issue. Thanks
@nanaeaubry I was asked by a coworker to submit a support request in addition to this bug report. The case number is: 03479596 We will followup with Technical Support. I will also update you if/when I can share this layer as public.
@nanaeaubry That layer should be accessible. It's shared as public and I am able to get to it after logging out of any Esri or Enterprise accounts. Let me know if you're still having issues. The URL above should open. Thanks
@authalic I get this when trying to access the link:
@nanaeaubry I'm not quite sure why you would be getting that 403 error. This deployment is hosted on Google Cloud. I'm asking our networking person if there might be some kind of restrictions on who could access it. It's public data, so we're a bit concerned that it can't be accessed from where you are.
Meanwhile, I met with Yanlin from Esri Premium Support Services today. We opened a support request on this issue (Esri Case #03479596) I showed him the error I was getting. We were not able to find an explanation for it. He's still looking. But, I found that if I modify the feature layer query to exclude geometries, the issue goes away. This is the modified query:
featset = featlyr.query(return_geometry=False)
This feature layer contains 17 fields and a large number of features, but other layers are bigger. Yanlin thought that maybe the query was requesting more data than something could handle. The geometries in this layer are probably among the biggest and most complex. Removing the geometries from the query prevented the crash, but we still don't have an explanation for what was happening to cause it.
@authalic Interesting we will investigate what we can on our end and come back with any updates here. There's a chance the support case will make it to us as well.
Thanks for all the detail this is helpful for us to continue investigating!
@authalic I just tested your service endpoint and it seems like everything completed. 500 errors are issues with the server/service. Try raising the # of SOC instances on this service and see if the 500 errors go away.
@achapkowski Thanks. I am still able to reproduce the original Python API error from the layer.py module. The 500 error was not part of the original issue raised here. I have found a workaround which enables me to accomplish what I need, so I'm not hung up on this, but it looks like it's still happening.
When I request the featureset from Layer 22 using: featset = featlyr.query() I get the exception: AttributeError: 'dict' object has no attribute 'lower' (see full traceback in the orignal bug report) When I request the featureset and exclude geometries, it works. This line does not raise an exception: featset = featlyr.query(return_geometry=False) None of the other layers on the feature server (approx 50) raise that exception when geometries are requested. Something in layer 22 is creating an exception in the site-packages\arcgis\features\layer.py module.
@achapkowski I will also attempt to increase the number of SOC instances and report here if that helps fix the error. Thanks. I overlooked that in my previous comment.
@achapkowski I just increased the maximum number of dedicated instance pool instances from 2 to 4, restarted the service, and ran the code again. I'm still getting the same errors. The first exception is: Exception: {'code': 500, 'message': 'Error performing query operation', 'details': []} and during the handling of that, another exception is encountered: AttributeError: 'dict' object has no attribute 'lower'
ok, let me see if I can reproduce it.