Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.9k stars 1.1k forks source link

content.clone_items fails saying item_id exists already while content.get returns none for same item_id #1486

Open FeralCatColonist opened 1 year ago

FeralCatColonist commented 1 year ago

Describe the bug content.clone_items fails for an application saying that the item_id exists currently; however, a content.get call returns nothing for the same item_id.

To Reproduce Steps to reproduce the behavior:

import arcgis
import keyring

dev_admin_user = keyring.get_password("dev-portal", "dev-portal_admin")
dev_admin_pass = keyring.get_password("dev-portal", dev_admin_user)
prod_admin_user = keyring.get_password("prod-portal", "prod-portal_admin")
prod_admin_pass = keyring.get_password("prod-portal", prod_admin_user)

gis_dev = arcgis.gis.GIS(r"https://dev-data.prospertx.gov/portal", dev_admin_user, dev_admin_pass)
gis_prod = arcgis.gis.GIS(r"https://data.prospertx.gov/portal", prod_admin_user, prod_admin_pass)

dict_items_to_transfer = {
    "app_cityworks_sso": "00dba4e70cfc4be0aa373d778e45ea7a",
    "app_edit_grease_trap" : "235195a4c458400a8d1f20110001a46f",
    "app_edit_plant_inventory": "95cd1ec9ec69459086996e77f9b6c198",
    "app_fire_mapbook": "436f3be7736144a1bc50939208fa7e6d",
    "app_imaps": "d5cc3805e88b4a86b468b61c32f5bb2d",
    "app_speed_limits": "bb443aaf25c84ec3baa5310931af45e0",
    "app_str_tracking": "06ab9fffe88d415a90e061f5fbd3a260",
    "app_tax_permits": "9e64d3c40c414aadad3b39730130e907",
    "app_thoroughfare_plan": "a1024d9ddcad42aa8b443f6e83a61158",
    "map_edit_grease_trap": "edeab74f2ede48c9851b4ff8d162af2a",
    "map_edit_plant_inventory": "677c386c8f06477298198c1882704152",
    "map_fire_mapbook": "a6a324f03f7341089c1269ee5dbe2873",
    "map_imaps": "a084d645ee4d42cfba4972cdd2d1a03e",
    "map_nearmap": "ad27ac5788da4ee6931a6e01f3e37fce",
    "map_speed_limits": "9d9c780caa494ed6a3382a284a4d8942",
    "map_str_tracking": "872f2112e7e44df983bf28ed7ebb5e75",
    "map_tax_permits": "d66c0d56873544ab978109b07b49b245",
    "map_thoroughfare_plan": "6fda919d399049cbb25817e885e2b7f4"
}

for key, value in dict_items_to_transfer.items():
    print(f"Transferring item id:\n\t{value} | has short name: {key}")
    item_to_clone = gis_prod.content.get(value)
    #print(item_to_clone.get_data())
    try:
        print(f"\tDoes it exist?\t{gis_dev.content.get(value)}")
        gis_dev.content.clone_items(
            items = [item_to_clone],
            copy_data = False,
            search_existing_items = True,
            preserve_item_id = True
            )
    except Exception as e:
        print(f"\tSomething went wrong:\n\t{e}\n----------")
        pass

error:

#user generated
Transferring item id:
    235195a4c458400a8d1f20110001a46f | has short name: app_edit_grease_trap
    Does it exist?  None
    Something went wrong:
#actual exception
("Failed to create Web Mapping Application Editing_PublicWorks_GreaseInterceptors: Item with Id '235195a4c458400a8d1f20110001a46f already exists[.\n](https://file+.vscode-resource.vscode-cdn.net/b%3A/Repository/Enterprise_Transfer/n)(Error Code: 400)", <Item title:"Editing_PublicWorks_GreaseInterceptors" type:Web Mapping Application owner:REDACTED>)

Screenshots Script Output for Loop image User content page in portal/sharing/rest/content/users backend, shows no items that match items asserted to exist. image

Expected behavior If an item cannot be returned from content.get() then content.clone_items() should not assert that the item already exists.

Platform (please complete the following information):

Additional context

dmoiler commented 9 months ago

Thanks for reporting this @FeralCatColonist. Happy to hear I'm not the only one and that it is indeed a bug.

I've got the same error during a migration from a 10.8.1 to 11.1 migration (big jump I know!).

I've tested this with arcgis 2.2.0 & 2.1.0.2 and both have return the same error.

Looking forward to an upcoming version that resolves this for future migrations. Even with WAB being deprecated there will be some migrations of legacy apps over the next couple of years that could use this.