clone_items throws "IndexError: list index out of range" when there are nested repeats in the featureservice
- Dominant language
- Python
- Stars
- 2.2k
- Forks
- 1.2k
- Avg merge
- 2h 40m
- Merged PRs (30d)
- 2
Description
**Describe the bug**
A clear and concise description of what the bug is.
When I use the code to clone items for feature service and if it has nested repeats I get the error and fails to clone.
**To Reproduce**
I have a feature service with following
FeatureLayer (id=0)
Table 1(id=1) --> related to layer 0
Table 2(id=2) --> related to Table 1
Steps to reproduce the behavior:
```python
copydata = True
item_id_test ='a8a819c2efab4c8ab3aaed5bfbe74b14'
print(datetime.now().strftime("%Y/%m/%d, %H:%M:%S"))
source = GIS(source_enterprise_url, source_username, source_password, use_gen_token=True)
target = GIS(target_arcgisonline_url, target_username, target_password, use_gen_token=True)
#print("s",source)
#print("t",target)
it = source.content.get(item_id_test)
target_user=target_username
foldername='0_Migration_Test_Folder'
cloned_items = target.content.clone_items(items=[it], folder=foldername, owner=target_user, copy_data=copydata,use_org_basemap=True)#,item_mapping=map_service_item_mapping)
```
error:
```python
{
"name": "_ItemCreateException",
"message": "('Failed to create Feature Service SERVICENAME: list index out of range', )",
"stack": "---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
c:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\lib\\site-packages\\arcgis\\_impl\\common\\_clone.py in clone(self)
3924 ]
-> 3925 self._add_features(
3926 new_layers,
c:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\lib\\site-packages\\arcgis\\_impl\\common\\_clone.py in _add_features(self, layers, relationships, layer_field_mapping, spatial_reference)
2786 object_id_field = layers[layer_id].properties[\"objectIdField\"]
-> 2787 object_id_mapping[layer_id] = {
2788 layer_features[i][\"attributes\"][object_id_field]: add_results[i][
c:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\lib\\site-packages\\arcgis\\_impl\\common\\_clone.py in (.0)
2787 object_id_mapping[layer_id] = {
-> 2788 layer_features[i][\"attributes\"][object_id_field]: add_results[i][
2789 \"objectId\"
IndexError: list index out of range
During handling of the above exception, another exception occurred:
_ItemCreateException Traceback (most recent call last)
~\\AppData\\Local\\Temp\\ipykernel_29612\\2784937216.py in ()
14 target_user=\"targetuser\"
15 foldername='0_Migration_Test_Folder'
---> 16 cloned_items = target.content.clone_items(items=[it], folder=foldername, owner=target_user, copy_global_ids=True,copy_data=copydata,use_org_basemap=True)#,item_mapping=map_service_item_mapping)
17
18
c:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\lib\\site-packages\\arcgis\\gis\\__init__.py in clone_items(self, items, folder, item_extent, use_org_basemap, copy_data, copy_global_ids, search_existing_items, item_mapping, group_mapping, owner, preserve_item_id, **kwargs)
8560 wab_code_attach=kwargs.pop(\"copy_code_attachment\", True),
8561 )
-> 8562 return deep_cloner.clone()
8563
8564 def bulk_update(
c:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\lib\\site-packages\\arcgis\\_impl\\common\\_clone.py in clone(self)
1320 else:
1321 with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
-> 1322 results = executor.submit(self._clone, executor).result()
1323 return results
1324
c:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\lib\\concurrent\\futures\\_base.py in result(self, timeout)
444 raise CancelledError()
445 elif self._state == FINISHED:
--> 446 return self.__get_result()
447 else:
448 raise TimeoutError()
c:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\lib\\concurrent\\futures\\_base.py in __get_result(self)
389 if self._exception:
390 try:
--> 391 raise self._exception
392 finally:
393 # Break a reference cycle with the exception in self._exception
c:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\lib\\concurrent\\futures\\thread.py in run(self)
56
57 try:
---> 58 result = self.fn(*self.args, **self.kwargs)
59 except BaseException as exc:
60 self.future.set_exception(exc)
c:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\lib\\site-packages\\arcgis\\_impl\\common\\_clone.py in _clone(self, excecutor)
1294 if item:
1295 item.delete()
-> 1296 raise ex
1297
1298 level += 1
c:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\lib\\concurrent\\futures\\thread.py in run(self)
56
57 try:
---> 58 result = self.fn(*self.args, **self.kwargs)
59 except BaseException as exc:
60 self.future.set_exception(exc)
c:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\lib\\site-packages\\arcgis\\_impl\\common\\_clone.py in clone(self)
3994 return new_item
3995 except Exception as ex:
-> 3996 raise _ItemCreateException(
3997 \"Failed to create {0} {1}: {2}\".format(
3998 original_item[\"type\"], original_item[\"title\"], str(ex)
_ItemCreateException: ('Failed to create Feature Service SERVICENAME: list index out of range', )"
}
```
**Platform (please complete the following information):**
- OS: [Windows 10, ArcGIS Pro 3.2]
- Browser [Visual Studio Code]
- Python API Version '2.2.0.1'
**Additional context**
Cloning contents from ArcGIS Enterprise to ArcGIS Online
Also I would like to mention that if the process takes longer than 60 min, it will fail with invalid token error. I tried several ways to see if the expiry time of token to be longer, but I am not able to do so. When using rest API, I am able to have longer expiring token but not with the Python API using "arcgis.gis".
Contributor guide
Assessment
This issue has not been assessed yet.