Select to view content in your preferred language

'name' property in python arcgis.gis.Item object

123
1
Tuesday
MatthiasBoucher
New Contributor II

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 :

MatthiasBoucher_0-1719372182416.png

 

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 :

  • How/when is the 'name' property of an item initialized or updated, and is it possible to do it either manually in the brower or with python ? Is it normal to have a None value for this property ?
  • There is obviously an issue with the Collaboration which doesn't transfer the properties identically from my portal to ArcGIS Online (None becomes ''), so is there a way to fix this behavior ?
  • The python function clone_items works when the 'name' is None, but crashes when the 'name' propery is equals to '', so it is not robust enough for my workflow. Is there another way to clone such items ?

 

PS : I work with an ArcGIS Enterprise 10.9.1

 

Thank you for your help.

0 Kudos
1 Reply
EarlMedina
Esri Regular Contributor

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.

0 Kudos