Skip to content

Item object copy_feature_layer_collection() method does not work if there are relationships set (2.4.3) #2536

Description

@Clubdebambos

Describe the bug
Item object copy_feature_layer_collection() method does not work if there are relationships set. Without a relationship for any of the feature layer and tables it works just fine, but attempt with a relationship for a layer/table and it fails. Testing from standalone script and AGOL Notebook.

To Reproduce
Steps to reproduce the behavior:

from arcgis.gis import GIS

## the name of the new service to create
new_service_name = "TESTING_DEEP_COPY"

## the item id of the service to copy
item_id = "FS_ITEM_ID"

agol = GIS("home")

item = agol.content.get(item_id)

## get the layer indexes
layers = list(range(len(item.layers)))

## get the table indexes
tables = list(range(len(item.tables)))

## copy the item - copies the shell, not data is added to the layers/tables
copied_item = item.copy_feature_layer_collection(
    service_name = new_service_name,
    layers = layers,
    tables = tables,
    description = item.description,
    snippet = item.snippet
)

error:

Traceback (most recent call last):
  File "C:\Users\glenb\Documents\Blogs\AGOL\Deepcopy_of_FLC\deepcopy_of_flc_maintain.py", line 48, in <module>
    copied_item = item.copy_feature_layer_collection(
        service_name = new_service_name,
    ...<3 lines>...
        snippet = item.snippet
    )
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py", line 15631, in copy_feature_layer_collection
    res = fs_manager.add_to_definition(json_dict=add_defs)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features\managers.py", line 3165, in add_to_definition
    res = self._con.post(adddefn_url, params)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1530, in post
    return self._handle_response(
           ~~~~~~~~~~~~~~~~~~~~~^
        resp=resp,
        ^^^^^^^^^^
    ...<3 lines>...
        force_bytes=kwargs.pop("force_bytes", False),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1005, in _handle_response
    self._handle_json_error(data["error"], errorcode)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1028, in _handle_json_error
    raise Exception(errormessage)
Exception: Unable to add feature service definition.
Invalid definition for System.Collections.Generic.List`1[ESRI.ArcGIS.SDS.Metadata.LayerCoreInfo]
Exception has been thrown by the target of an invocation.
(Error Code: 400)

Screenshots
If applicable, add screenshots to help explain your problem.

Expected behavior
I expect the copy_feature_layer_collection() to do as it should whether relationships are set or not, or at least stipulate that this is a limitation and handle it gracefully rather than erroring.

Platform (please complete the following information):

  • OS: Windows 11
  • Browser: Chrome/Edge
  • Python API Version: 2.4.3

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