IndexError and corrupted hosted feature service when using the ViewManager create method
- Dominant language
- Python
- Stars
- 2.2k
- Forks
- 1.2k
- Avg merge
- 2h 40m
- Merged PRs (30d)
- 2
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:
```python
# 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:
```python
Traceback (most recent call last):
File "C:\Users\", line 140, in
main()
~~~~^^
File "C:\Users\", 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.
Contributor guide
Assessment
This issue has not been assessed yet.