Select to view content in your preferred language

clone_items error KeyError: 'dataSource'

69
3
Friday
chris_del101
Occasional Contributor

I'm trying to clone  a dashboard. I've cloned other dashboards before without this happening.

It's very basic dashboard with one map and a gauge and date picker. It's just for testing. It's published and has an id and works via portal.

from arcgis.gis import GIS
id = "71cf8cc7573f400b845ce79a772d7b2a" #actual id of dashboard
src=GIS(url=url,
                      username=username,
                      password=password,
                      verify_cert=True)
trg = GIS(url=url,
                      username=username2,
                      password=password2,
                      verify_cert=True)
db = src.content.get(id)
trg.content.clone_items(items=[db])

 

 

 

 

 

This immediately fails. Was something mandatory left out in the construction process?

 

 

Traceback (most recent call last):
  File "C:\Users\me\code\source\repos\arcgis-cloner\src\portal_app.py", line 211, in run_item_clone
    cloned_item = env.content.clone_items(
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\__init__.py", line 8738, in clone_items
    deep_cloner = clone._DeepCloner(
                  ^^^^^^^^^^^^^^^^^^
  File "c:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\_impl\common\_clone.py", line 130, in __init__
    dash_list = self._clone_dashboard(item)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\_impl\common\_clone.py", line 157, in _clone_dashboard
    if dataset["dataSource"]["itemId"] not in item_list:
       ~~~~~~~^^^^^^^^^^^^^^
KeyError: 'dataSource'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\__init__.py", line 8738, in clone_items
    deep_cloner = clone._DeepCloner(
                  ^^^^^^^^^^^^^^^^^^
  File "c:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\_impl\common\_clone.py", line 125, in __init__
    item["type"] == "Dashboard"
    ~~~~^^^^^^^^
TypeError: string indices must be integers, not 'str'

 

 

 

Edit: fixed typo in code. block 1 demo had missing example lines

Tags (1)
0 Kudos
3 Replies
CodyPatterson
MVP Regular Contributor

Hey @chris_del101 

The major issue  comes from this here:

CodyPatterson_0-1736790040299.png

The information being entered is not correctly registering as a dictionary, as item['type'] is expecting:

item = {"type": "something"}

I would verify the item that you're attempting to clone is the correct id, along with ensuring that it is the correct type of item you would like to attempt to clone, I assume item in this case would be None or "".

Cody

0 Kudos
chris_del101
Occasional Contributor

Hi @CodyPatterson, Thanks for replying!

That is coming from the arcgis source, not from me. It seems the code block in my post was blank, so not sure if U saw that. I reposted it. Apologies if you response was based on my inaccuracy.

I call the function in the normal way, the same I do with all other objects, but there I get that error. 

The clone_items function does not take a type. It should get that internally from the content obj that is passed in. And, the item works when I view in portal, so it's not erroring out or anything obvious. I created it myself using dashboard builder.

The id is the correct one. 

0 Kudos
BijanTaheri
Occasional Contributor

I think this is a problem in the main arcgis clone functions.

It assumes that your dashboard element has a key "dataSource", which it seems yours doesn't. I don't know how your dashboard is set up?

I have had a similar problem with the (now deprecated) experience builder clone function, where i had to change the core code to make it work.
So you can try to change the core code yourself, and test if it works just this once - you can always change it back.

Try changing the file:"c:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\_impl\common\_clone.py"
Line 157

From this:
if dataset["dataSource"]["itemId"] not in item_list:


To this:
if dataset.get("dataSource") and dataset["dataSource"]["itemId"] not in item_list:  

This will check if the "dataSource" key exists, before attempting to get the itemIds.

I can't test it without having your dashboard, so maybe you can try for your self.

 

0 Kudos