Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty 'name' property of an arcgis item object causes crash when trying to clone #1872

Open
Miralupa opened this issue Jul 18, 2024 · 0 comments
Assignees
Labels

Comments

@Miralupa
Copy link

Describe the bug
An item with an empty name will cause a crash if this item is cloned.

To Reproduce
Steps to reproduce the behavior:
No particular piece of code, just a simple call to 'clone_items' will trigger the crash when an item has an empty name.

agol.content.clone_items(items=[itemWithEmptyName])

Here is my workflow that lead me to this problem : I share some items of my portal through a collaboration towards ArcGIS Online. Then, once in ArcGIS Online, I try to clone the recently appeared items using the arcgis Python API. However, a crash occurs during the 'clone_items' function call of the arcgis Python API. The empty 'name' property of the item is the cause of the crash. In my portal source item, the item.name is None (not on all of my items, but on some of them. I don't know if it is normal or if it is legacy after upgrading my arcgis enterprise). Once such item is created in ArcGIS Online through collaboration, the name property is not None anymore, but it became an empty string ''. And this empty string is the cause of the crash during the clone_items step of my workflow.

error:
in arcgis Python 2.3.0

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 2945, 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 2850, in _get_unique_name
if name[0].isdigit():
~~~~^^^
IndexError: string index out of range

Expected behavior
In my opinion, 2 or maybe 3 problems occur during this workflow :

  1. I don't know if the 'name' property of an item should be None or empty in the first place. I don't know how this property is forged and what are its purprose and usages (equals to 'title' most of the case), so maybe this isn't a real problem. But just for you to know : it can happen in production.
  2. the collaboration between my portal and ArcGIS Online doesn't recreate the item identically, as a None item.name becomes an empty string. I would expect an None property to remain None after collaboration. Maybe this problem should be forwarded to another dev team that works on collaboration.
  3. And empty name causes the crash in the python clone_items call. It is due to the following piece of code line 2941 of the _clone.py script of the arcgis Python module:
name = original_item["name"]
if name is None:
    name = os.path.basename(os.path.dirname(original_item["url"]))

name = re.sub("\W+", "_", name)
name = self._get_unique_name(self.target, name)

The test 'if name is None' might not be robust enough and should treat the empty string too (or do something else accordingly) before the 'self._get_unique_name' call in which the 'name[0]' crashes.

Platform:

  • OS: Windows (irrelevant to the problem)
  • Browser : Chrome (irrelevant to the problem)
  • Python API Version : crash reproduced in 1.8.5 and in 2.3.0
  • ArcGIS Enterprise : 10.91

Additional context
Original problem opened there, a colleague of yours pointed me here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants