Esri / Esri/arcgis-python-api

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

Aperta
#2,537 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
Python
Stelle
2.2k
Fork
1.2k
Merge medio
2h 40m
PR unite (30g)
2

Descrizione

**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.

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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia da arcgis/features/managers.py, in particolare da create_view e set_visible_fields_and_query, quindi segui il punto di ingresso ViewManager.create in arcgis/gis/__init__.py. Riproduci il traceback con un feature service ospitato a più layer usando query e visible_fields, e confronta la definizione del servizio prima e dopo. Il lavoro è completato quando la creazione della vista termina senza IndexError e il servizio padre continua a esporre i propri feature layer.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
api, backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
58/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.