Skip to content

IndexError and corrupted hosted feature service when using the ViewManager create method #2537

Description

@astjohn-RM

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.

Image Image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions