I am currently writing a python script to manipulate items, either from ArcGIS Online or from an ArcGIS Portal, and I am facing a problem due to the 'name' property of the arcgis.gis.Item object.
At first, I didn't know about this property (I am more familiar with 'title' or 'itemid'), so I don't know what value this property is supposed to contain, neither how to fill it. It is often identical to the 'title' property, but some of my items have the value None (I don't know if it is a legacy herited from previous versions of my portal).
I tried to update this property with the following piece of code, but it had no effect (eventhough the result was True) :
result = item.update(item_properties={'name': item.title})
It would be harmless most of the time, but the real problem I am facing occurs when I work with a collaboration between my ArcGIS Portal and ArcGIS Online. My items are shared as copies and, once copied into ArcGIS Online, I noticed that the items with a None 'name' suddendly have 'name' equals to the empty string ''. Later in my workflow I try to clone some of those items, but the function gis.content.clone_items crashes withe the following message :
Traceback (most recent call last):
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\_impl\common\_clone.py", line 2811, in clone
name = self._get_unique_name(self.target, name)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\_impl\common\_clone.py", line 2719, in _get_unique_name
if name[0].isdigit():
IndexError: string index out of range
Indeed, the clone function checks if the 'name' property of the item to clone is None, but doesn't check the empty string case, hence the crash :
To sum up : I am unable to clone items that have transited through a collaboration, because of their 'name' property that has been transformed from None to ''.
So, my questions are :
PS : I work with an ArcGIS Enterprise 10.9.1
Thank you for your help.
Solved! Go to Solution.
Hello Matthias. I'll do my best to be helpful here.
1. I'm not sure why both name/title exist nor when name is initialized, but you can set the value of "name" locally without updating pushing the update. I'd be curious to see if this fixes your problem. Can you trick clone_items into working with one of the bad items by setting the name property beforehand?
item.name = "test"
2. I'm not sure what this is about, but it seems like there is some incomplete logic. Again, I would try the manual set mentioned in #1 and see if that is enough to fix it. You might also consider logging this as an issue here: Issues · Esri/arcgis-python-api · GitHub
3. You could log another issue for this and point out the line number/block where the issue is happening. I suspect that updating the line "if name is None" to "if not name" would fix the problem as it should handle both None and empty strings. You could even try this fix yourself and see if it fixes the problem! I would just advise to be careful to change it back to the original or else use a development python environment.
Hello Matthias. I'll do my best to be helpful here.
1. I'm not sure why both name/title exist nor when name is initialized, but you can set the value of "name" locally without updating pushing the update. I'd be curious to see if this fixes your problem. Can you trick clone_items into working with one of the bad items by setting the name property beforehand?
item.name = "test"
2. I'm not sure what this is about, but it seems like there is some incomplete logic. Again, I would try the manual set mentioned in #1 and see if that is enough to fix it. You might also consider logging this as an issue here: Issues · Esri/arcgis-python-api · GitHub
3. You could log another issue for this and point out the line number/block where the issue is happening. I suspect that updating the line "if name is None" to "if not name" would fix the problem as it should handle both None and empty strings. You could even try this fix yourself and see if it fixes the problem! I would just advise to be careful to change it back to the original or else use a development python environment.
Hello Earl, and thank you for your answers ! I've tried your different solutions and here are my results :
name = original_item["name"]
An empty name will consequently still crash, as locally modified properties are overwritten.
2. I created the ticket here : here . Wait and see !
3. Same answer
We can close this thread depending on their upcoming answer.
Hey, did you ever solve this? I am looking for anyway to change the name or title of portal items (or server, or in any other possible way). The item definitions (in json) do not have a title field, but I do see a name field , but it's in the admin section which seemingly cannot be changed.
"adminServiceInfo": {
"database": {
"datasource": {
"name": "/enterpriseDatabases/AGSDataStore_abc123"
}
},
"name": "My_feature_service_xyz",
"type": "FeatureServer",
"status": "Started"
}
}
Hello Chris
My original problem (Python crash with "IndexError: string index out of range") has been marked as resolved in the next release by the arcgis python api team (https://github.com/Esri/arcgis-python-api/issues/1872).
However, regarding the possibility to alter the name/title of portal items, I didn't push any further. It might be possible locally, as suggested by Earl's answer above, but I doubt it is possible to persist those changes on the portal side.