IndexError and corrupted hosted feature service when using the ViewManager create method
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 58/100
Research direction
Start with arcgis/features/managers.py, especially create_view and set_visible_fields_and_query, then follow the ViewManager.create entry point in arcgis/gis/init.py. Reproduce the traceback with a multi-layer hosted feature service using query and visible_fields, and compare the service definition before and after. Done means view creation completes without IndexError and the parent service still exposes its feature layers.
Written by the indexing model from the issue text.
Description
Describe the bug
The create method in the ViewManager class throws an IndexError when using the query or visible_fields parameters, for hosted feature service containing more than one feature layer.
Removing the query and visible_fields parameters also throws the IndexError after successfully creating just one view from the parent hosted feature service.
It seems to corrupts the parent hosted feature service definition in some way(s), where the layers are no longer recognized via the sharing REST endpoint and in the view creation/update UI.
See screenshots for examples of expected versus corrupted.
To Reproduce
Steps to reproduce the behavior:
# example parameters
view = {
"name": "Sanitary Lift Stations view",
"hfl_itemid": sanitary_hfl_itemid,
"layer_id": 0,
"vis_field": ["*"],
"filter": "Status <> 'Abandoned' AND StructureType = 'Lift Station'"
}
view_item = flyr_item.view_manager.create(
name=new_view_name,
view_layers=[flyr_item.layers[view['layer_id']]],
allow_schema_changes=False,
updateable=False,
capabilities="Query",
preserve_layer_ids=True,
query=view['filter'],
visible_fields=["OBJECTID", "GlobalID"] + view['vis_field']
)
error:
Traceback (most recent call last):
File "C:\Users\<path to .py>", line 140, in <module>
main()
~~~~^^
File "C:\Users\<path to .py>", line 75, in main
view_item = flyr_item.view_manager.create(
name=view_name,
...<5 lines>...
query="Status <> 'Abandoned' AND StructureType = 'Lift Station'" if view_name == "Sanitary_Lift_Stations_view" else "Status <> 'Abandoned' AND (StructureType = 'Outfall' OR StructureType = 'Grass Swale Outfall')"
)
File "C:\Users\AStJohn\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\arcgis\gis\__init__.py", line 20804, in create
return mgr.create_view(
~~~~~~~~~~~~~~~^
name=name,
^^^^^^^^^^
...<14 lines>...
query=query,
^^^^^^^^^^^^
)
^
File "C:\Users\AStJohn\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\arcgis\features\managers.py", line 3110, in create_view
set_visible_fields_and_query(item, visible_fields, query, gis)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AStJohn\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\arcgis\features\managers.py", line 3078, in set_visible_fields_and_query
fields = item.layers[0].properties["fields"]
~~~~~~~~~~~^^^
IndexError: list index out of range
Screenshots
After running the view create() method, with OR without the query and visible_fields parameters, the UI no longer recognizes feature layers and only tables are available when creating or updating the view.
Expected behavior
This API call has been working for over a year in our scripts, creating hundreds of views programmatically. I expect that the views be created with query and visible_fields parameters defined and that the parent hosted feature service is not altered in any detrimental way.
Platform (please complete the following information):
- OS = Windows 11
- Browser = Chrome
- Python API Version = 2.4.2
Additional context
Add any other context about the problem here, attachments etc.
- Dominant language
- Python
- Stars
- 2.2k
- Forks
- 1.1k
- Avg merge
- 2h 40m
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Esri/arcgis-python-api
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Esri/arcgis-python-api#2513 · 1 comment ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Esri/arcgis-python-api#2453 · 3 comments ·
-
documentation enhancement
Difficulty 1/5 Under an hour Newbie friendliness 76/100
Esri/arcgis-python-api#2097 · 1 comment ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 56/100
Esri/arcgis-python-api#2531 · 1 comment ·
-
bug
Esri/arcgis-python-api#2527 · 4 comments · 1 assignee ·
All issues in Esri/arcgis-python-api
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100