Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.89k stars 1.1k forks source link

clone_items gives key error in _FeatureServiceDefinition _add_features method when FeatureServer does not contain layer with identifier 0 #2146

Closed rkraujutis closed 19 hours ago

rkraujutis commented 2 days ago

Describe the bug

Cloning item 05ace607387b44d7b8537265e646988d gives error:

File "/opt/conda/lib/python3.12/site-packages/arcgis/_impl/common/_clone.py", line 2826, in _add_features
            layers[0].container.manager.update_definition(edit_params)
            ~~~~~~^^^
            KeyError: 0

Key error is raised, because layers parameter is dictionary with layer id 35.

To Reproduce Steps to reproduce the behavior:

source_content:ContentManager = source_gis.content
source_item = source_content.get("05ace607387b44d7b8537265e646988d")

target_content:ContentManager = target_gis.content

try:
    for cloned_item in target_content.clone_items([
            source_item
        ],
        search_existing_items = False,
        preserve_editing_info = True,
    ):
        logger.info(f'Cloned item: {cloned_item.itemid} {cloned_item}')
except:
    logger.warning(f"Failed clone {source_item.itemid}", exc_info=True)

error:

Traceback (most recent call last):
  File "/REDACTED.py", line 27, in REDACTED
    for cloned_item in target_content.clone_items([
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.12/site-packages/arcgis/gis/__init__.py", line 8757, in clone_items
    return deep_cloner.clone()
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.12/site-packages/arcgis/_impl/common/_clone.py", line 1347, in clone
    results = executor.submit(self._clone, executor).result()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.12/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/opt/conda/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.12/site-packages/arcgis/_impl/common/_clone.py", line 1321, in _clone
    raise ex
  File "/opt/conda/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.12/site-packages/arcgis/_impl/common/_clone.py", line 4270, in clone
    raise _ItemCreateException(
arcgis._impl.common._clone._ItemCreateException: ('Failed to create REDACTED)

Expected behavior

Expected cloned item appear in target.

Platform (please complete the following information):

achapkowski commented 1 day ago

We will have a fix for this in the next release.