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

Vector Tile Service Cloning Fails with Errors in ArcGIS Python API v2.4.0 #2243

Closed
pmd84 opened this issue Mar 26, 2025 · 5 comments
Closed
Assignees
Labels

Comments

@pmd84
Copy link

pmd84 commented Mar 26, 2025

Describe the bug

When attempting to clone Vector Tile Service or Vector Tile Layer items using the clone_items() method in ArcGIS Python API v2.4.0, the process fails.

This affects the ability to clone Vector Tile Services which worked properly in previous versions (confirmed working in v2.3.0).

To Reproduce

Steps to reproduce the behavior:

import arcgis
from arcgis.gis import GIS

# Connect to your portal
gis = GIS("portal_url", "username", "password")

# Find Vector Tile Layer items
vtl_items = gis.content.search("title:*tile_layer*", item_type="Vector Tile Layer", max_items=2)

# Create target folder if needed
if "test-copy-folder" not in [f.title for f in gis.content.folders]:
    gis.content.create_folder("test-copy-folder")

# Try to clone the items to the target folder
for item in vtl_items:
    print(f"\nCloning {item.title}, item_type: {item.type}")
    try:
        cloned_item = gis.content.clone_items(
            items=[item],
            owner=gis.users.me,
            folder="test-copy-folder",
            search_existing_items=False
        )
        print(f"Cloned {item.title} to test-copy-folder")
    except Exception as e:
        print(f"Failed to clone {item.title}: {e}")

Error:

"Failed to create Vector Tile Service [tile_layer_name]: cannot access local variable 'r' where it is not associated with a value"

Expected behavior

The Vector Tile Layer items should be successfully cloned to the target folder, as they were in previous versions of the ArcGIS Python API.

Platform (please complete the following information):

  • OS: Linux (Databricks)
  • Python API Version: 2.4.0
  • Environment: Databricks with Python 3.12

Additional context

  • This functionality worked properly in ArcGIS Python API v2.3.0
@pmd84 pmd84 added the bug label Mar 26, 2025
@nanaeaubry
Copy link
Contributor

@pmd84 Can you please post the longer error message so we can see where it is being thrown?

@nanaeaubry
Copy link
Contributor

nanaeaubry commented Mar 27, 2025

@pmd84
Also not relevant to this but just a small heads up that starting at 2.4.1 this line:
if "test-copy-folder" not in [f.title for f in gis.content.folders]:

Will need to be changed to:
if "test-copy-folder" not in [f.name for f in gis.content.folders.list()]:

And this:
gis.content.create_folder("test-copy-folder")

Will be changed to:
gis.content.folders.create("test-copy-folder")

@pmd84
Copy link
Author

pmd84 commented Mar 27, 2025

Hey @nanaeaubry

Here is the full traceback:

Cloning tile_layer, item_type: Vector Tile Service
Failed to clone tile_layer: ("Failed to create Vector Tile Service tile_layer: cannot access local variable 'r' where it is not associated with a value", None)
Traceback (most recent call last):
  File "/databricks/python/lib/python3.12/site-packages/arcgis/_impl/common/_clone.py", line 2298, in clone
    new_item = self._add_new_item(item_properties, data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/databricks/python/lib/python3.12/site-packages/arcgis/_impl/common/_clone.py", line 2181, in _add_new_item
    new_item = job.result()
               ^^^^^^^^^^^^
  File "/usr/lib/python3.12/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/databricks/python/lib/python3.12/site-packages/arcgis/gis/_impl/_content_manager/folder/core.py", line 468, in _add_async_streaming
    raise FolderException(str(r.text))
                              ^
UnboundLocalError: cannot access local variable 'r' where it is not associated with a value

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/.ipykernel/23474/command-2397696839422617-457867140", line 16, in <module>
    cloned_flyr = gis.content.clone_items(
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/databricks/python/lib/python3.12/site-packages/arcgis/gis/__init__.py", line 8757, in clone_items
    return deep_cloner.clone()
           ^^^^^^^^^^^^^^^^^^^
  File "/databricks/python/lib/python3.12/site-packages/arcgis/_impl/common/_clone.py", line 1347, in clone
    results = executor.submit(self._clone, executor).result()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/databricks/python/lib/python3.12/site-packages/arcgis/_impl/common/_clone.py", line 1321, in _clone
    raise ex
  File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/databricks/python/lib/python3.12/site-packages/arcgis/_impl/common/_clone.py", line 2311, in clone
    raise _ItemCreateException(
arcgis._impl.common._clone._ItemCreateException: ("Failed to create Vector Tile Service tile_layer: cannot access local variable 'r' where it is not associated with a value", None)

@nparavicini7
Copy link
Collaborator

@pmd84 we actually already have a pending fix for this for our next release. Thank you for reporting it!

@pmd84
Copy link
Author

pmd84 commented Mar 27, 2025

Great, thanks!

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

3 participants