-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Describe the bug
Hello,
I'm trying to clone an hosted table that has a custom objectid/objectidfield and it's unfortunately not taken into account which is causing a crash.
Here is the original hosted table objectid field definition (see the name and alias both being "OBJECTID" in all caps). Note: The objectidField is correctly pointing to it.
{
"nullable": false,
"editable": false,
"defaultValue": null,
"domain": null,
"name": "OBJECTID",
"length": 8,
"alias": "OBJECTID",
"type": "esriFieldTypeOID"
}To Reproduce
Steps to reproduce the behavior:
cloned_items = target_gis.content.clone_items(
items=[item],
copy_data=True,
copy_global_ids=True,
preserve_editing_info=True,
copy_code_attachment=True,
preserve_item_id=True
)error:
Traceback (most recent call last):
File "C:\Users\USER_ID\AppData\Local\Programs\Python\Python310\lib\site-packages\arcgis\_impl\common\_clone.py", line 4070, in clone
self._add_features(
File "C:\Users\USER_ID\AppData\Local\Programs\Python\Python310\lib\site-packages\arcgis\_impl\common\_clone.py", line 2902, in _add_features
object_id_mapping[layer_id] = {
File "C:\Users\USER_ID\AppData\Local\Programs\Python\Python310\lib\site-packages\arcgis\_impl\common\_clone.py", line 2903, in <dictcomp>
layer_features[i]["attributes"][object_id_field]: add_results[i][
KeyError: 'objectid'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\USER_ID\Documents\data-migration\Content Migration\create_common_items.py", line 24, in <module>
cloned_items = target_gis.content.clone_items(
File "C:\Users\USER_ID\AppData\Local\Programs\Python\Python310\lib\site-packages\arcgis\gis\__init__.py", line 9735, in clone_items
return deep_cloner.clone()
File "C:\Users\USER_ID\AppData\Local\Programs\Python\Python310\lib\site-packages\arcgis\_impl\common\_clone.py", line 1358, in clone
results = executor.submit(self._clone, executor).result()
File "C:\Users\USER_ID\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 446, in result
return self.__get_result()
File "C:\Users\USER_ID\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 391, in __get_result
raise self._exception
File "C:\Users\USER_ID\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "C:\Users\USER_ID\AppData\Local\Programs\Python\Python310\lib\site-packages\arcgis\_impl\common\_clone.py", line 1332, in _clone
raise ex
File "C:\Users\USER_ID\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "C:\Users\USER_ID\AppData\Local\Programs\Python\Python310\lib\site-packages\arcgis\_impl\common\_clone.py", line 4290, in clone
raise _ItemCreateException(
arcgis._impl.common._clone._ItemCreateException: ("Failed to create Feature Service Summarize_Attributes_for_Data_Extract: 'objectid'", <Item title:"Summarize_Attributes_for_Data_Extract" type:Feature Layer Collection owner:USER_ID>)Expected behavior
Cloning works correctly
Platform (please complete the following information):
- OS: Windows 11
- Python API Version: 2.4.2
Additional context
The issue occurs because of how the code handles the objectid field. Specifically, in arcgis/_impl/common/_clone.py at line 3703, the code tries to retrieve the new layer fields using:
new_fields = _deep_get(new_layer_properties, "fields")This will never work because new_layer_properties is a PropertyMap, and _deep_get expects a dict. As a result, new_fields ends up being None, which causes the logic that correctly handles the objectid to be skipped. Later, the code crashes when trying to access the objectid field because it has the wrong name.
Proposed Fix
Convert new_layer_properties to a dictionary before using _deep_get:
new_layer_properties = dict(new_layer.properties)According to the PropertyMap documentation, it can be converted to a dictionary using dict(obj).
If this isn’t the right place to submit this bug, please let me know where I should send it!
Thanks!