AGOL Notebook - item.export and the 'overwrite' argument

320
4
Jump to solution
10-29-2021 08:45 AM
AaronKoelker
Occasional Contributor III

I'm writing a notebook to export a hosted feature layer that I own as a File Geodatabase item into my content, using item.export . This would be used as a backup copy of my data, if needed. I then intend to schedule a task for the notebook to have it run on its own periodically -- and ideally would like it to overwrite the previously-created backup each time so that I don't have a bunch of items creating clutter and taking up storage space.

The item.export method has an argument for 'overwrite' to replace an existing item, which sounds like what I need, however I'm either misunderstanding it or it doesn't seem to be working correctly. When I set overwrite = true, it just creates a new item in my content with the same exact name.

 

 

dataitem = gis.content.get(#itemid)
backupname = f'{dataitem.title} Backup'
dataitem.export(backupname, 'File Geodatabase', parameters=None, wait=True, overwrite=True)

 

 

Any idea if this is a bug or intended behavior? Is there a better way to do this? I tried using a search to locate the previous backup so I could just delete it -- but even when feeding in the exact item name, it would occasionally pull up some other item in the org.

-Aaron
Tags (3)
0 Kudos
1 Solution

Accepted Solutions
AtmaMani
Esri Contributor

@AaronKoelkerwe decided to remove this parameter in v2.0 of the API (future release). The reason being, server does not establish a comprehensive item2item relationship for this use case, without which the API does not know which item to overwrite. Besides, we have a cardinality issue where a source item gets exported multiple times and the API would not know which of those items to overwrite.

The alternate is for you (as the user) to determine which item needs to be updated and call the https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.Item.update (DestinationItem.update()) method on it and pass the file that was returned from the SourceItem.export() call.

View solution in original post

4 Replies
AtmaMani
Esri Contributor

@AaronKoelkerthanks for reporting. This could be a bug on the Python API. The server does not actually support overwriting in this operation. I have logged a bug and we will investigate.

AaronKoelker
Occasional Contributor III

Bummer, but thanks for the info.

If anyone has any ideas for how to achieve this through another method, I'd love to hear it. Looking into using item.update now.

-Aaron
0 Kudos
AtmaMani
Esri Contributor

@AaronKoelkerwe decided to remove this parameter in v2.0 of the API (future release). The reason being, server does not establish a comprehensive item2item relationship for this use case, without which the API does not know which item to overwrite. Besides, we have a cardinality issue where a source item gets exported multiple times and the API would not know which of those items to overwrite.

The alternate is for you (as the user) to determine which item needs to be updated and call the https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.Item.update (DestinationItem.update()) method on it and pass the file that was returned from the SourceItem.export() call.

View solution in original post

AaronKoelker
Occasional Contributor III

Thanks for the update! I was able to get the item.update method to work for my purposes. Appreciate you taking a look.

-Aaron
0 Kudos