Repository navigation
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 rangeScreenshots
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.
Activity
kyroskoh commentedon Aug 13, 2026
Root cause (confirmed in arcgis 2.4.2 and 2.4.3)
This public repo is docs/samples only, so a library source PR cannot land here. The bug is in the closed-source package:
FeatureLayerCollectionManager.create_view(arcgis/features/managers.py), whichViewManager.createcalls.1. Parent hosted feature service corruption
Near the end of
create_view, after correctly resolving the new view item:update_item_datathen writes a filtereddata.layerssubset onto the parent. On multi-layer parents withview_layers=[one layer], the parent item JSON is overwritten so Portal/AGOL UI stops treating feature layers as layers (matches the screenshots).Suggested fix: delete the reassignment and keep the original view item:
2. IndexError on
item.layers[0]On AGOL,
future=Truereturns a Future that is never.result()'d beforeset_visible_fields_and_queryruns. Also, query/visible_fields are applied only tolayers[0], not every view layer.Suggested fix:
And in
set_visible_fields_and_query, guard empty layers and loop allflc.layers(treatvisible_fieldscontaining"*"as all fields visible).Temporary workaround for 2.4.2 / 2.4.3 users
Full usage, limits, removal steps, and tests:
misc/tools/issue_2537/README.mdon branchfix/issue-2537-viewmanager-create.Monkey-patch module:
fix_viewmanager_create_2537.pyOr copy the file next to your script:
It restores parent item JSON after create, awaits AGOL
add_to_definition, writes layer JSON onto the view, and applies query/visible_fields to each view layer.Mock / smoke tests
No live org required:
See
test_fix_viewmanager_create_2537.py.Removing the patch when Esri ships a fix
See When Esri releases a fix in the README. Short version:
arcgisrelease that includes the#2537fix (check the release notes).or:
view_manager.create(..., query=..., visible_fields=...)smoke test and confirm the parent servicedata.layersis unchanged.misc/tools/issue_2537/copy so the hotfix cannot be reapplied by mistake.Move Esri#2537 workaround into misc/tools/issue_2537 package.
nanaeaubry commentedon Aug 13, 2026
@kyroskoh @astjohn-RM Thank you for reporting this and thoroughly explaining the issue.
We are going to take a look at fixing.
Update: We found this issue but it is set to be fixed in 2.4.4 (Released in Fall). I will leave this issue open, after release please test and we can close if correctly addressed.
Add README for Esri#2537 ViewManager create workaround.
Add mock smoke tests for Esri#2537 ViewManager create workaround.
nanaeaubry commentedon Sep 10, 2026
@kyroskoh
A pre-release has been made with changes that fix this issue:
conda install -c esri/label/prerelease -c esri arcgis=2.4.4 arcgis-mapping=5.1.0 arcgis-geometry=1.1.0nanaeaubry commentedon Oct 9, 2026
@kyroskoh
We have released to conda, please test this and ensure it is working as expected. A pypi release will be made in the coming weeks