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 "Item with this filename already exists" when cloning service definitions #2150

Closed rkraujutis closed 1 day ago

rkraujutis commented 1 day ago

Describe the bug

Cloning two service definition items with same name fails with error:

Failed to create Service Definition migrantai_statistika: The item could not be added: {'error': {'code': 409, 'messageCode': 'CONT_0027', 'message': 'Item with this filename already exists. [itemId=8da4a062d5b041d0acdde1e03f0f33c7]

To Reproduce Steps to reproduce the behavior:

        source_content:ContentManager = source_gis.content
        source_item1 = source_content.get("7bfd09002db34485a86d82344f7f6b81")
        source_item2 = source_content.get("5eed32e40e144517991cf5c091d69d4b")

        target_content:ContentManager = target_gis.content

        cloned_items:list[Item] = []
        try:
            cloned_items = target_content.clone_items([
                    source_item1, source_item2,
                ],
                search_existing_items = False,
            )
        except:
            logger.warning(f"Failed clone {source_item1.itemid}", exc_info=True)

error:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.12/site-packages/arcgis/_impl/common/_clone.py", line 2298, in clone
    new_item = self._add_new_item(item_properties, data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.12/site-packages/arcgis/_impl/common/_clone.py", line 2181, in _add_new_item
    new_item = job.result()
               ^^^^^^^^^^^^
  File "/opt/conda/lib/python3.12/concurrent/futures/_base.py", line 449, 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/gis/_impl/_content_manager/folder/core.py", line 405, in _add_async_streaming
    raise FolderException(f"The item could not be added: {str(data)}")
arcgis.gis._impl._content_manager.folder._exceptions.FolderException: The item could not be added: {'error': {'code': 409, 'messageCode': 'CONT_0027', 'message': 'Item with this filename already exists. [itemId=8da4a062d5b041d0acdde1e03f0f33c7]', 'details': []}}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "REDACTED.py", line 28, in test_7bfd09002db34485a86d82344f7f6b81_5eed32e40e144517991cf5c091d69d4b
    cloned_items = 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 2311, in clone
    raise _ItemCreateException(
arcgis._impl.common._clone._ItemCreateException: ("Failed to create Service Definition migrantai_statistika: The item could not be added: {'error': {'code': 409, 'messageCode': 'CONT_0027', 'message': 'Item with this filename already exists. [itemId=8da4a062d5b041d0acdde1e03f0f33c7]', 'details': []}}", None)

Expected behavior

Expected cloned item appear in target.

Platform (please complete the following information):

Additional context

We are doing migration of ArcGIS Online content from one account to another. Cloning is being done in bulk. Some items causes the problems. They exists in source, but can't be cloned to target.

achapkowski commented 1 day ago

This is an expected, you should use reassign_to. https://developers.arcgis.com/python/latest/api-reference/arcgis.apps.hub.html#arcgis.apps.hub.initiatives.Initiative.reassign_to

rkraujutis commented 1 day ago

Why you providind sample of initiative reassign, while item identifier in examples are service definition files? Will the item be cloned from one GIS to another GIS? Cloning should not modify source item. Won't it be changed?