Select to view content in your preferred language

New AGOL Recycle Bin Breaks My Python Scripts That Overwrite Feature Service's With Sync Enabled

535
7
Jump to solution
07-09-2024 12:55 PM
LucasNeal
New Contributor II

Hi Everyone,

I work in a one-man GIS team, and one of my main tasks is processing data collected via Field Maps. Once the field workers sync their data collection devices, I process multiple feature classes into a new hosted feature service in AGOL.

Throughout my scripts process it checks if certain feature services exist and if they do to delete them. With the new recycle bin feature my script fails because it is not "permanently deleted" it is just hanging out in the recycle bin. I can manually navigate to the recycle bin and manually delete it and my script works like it normally does.

Has anyone else experienced something like this? I imagine there must be a way to permanently delete an item in AGOL  and have it not enter the recycle bin just deleted. 

0 Kudos
1 Solution

Accepted Solutions
JustinColville
Esri Contributor

@LucasNeal 

item delete has a "permanent" parameter available (https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#item).

"Optional boolean. Available in ArcGIS Online, setting to True will permanently delete the item rather than sending it to the recycle bin."

This might be what you are looking for?

View solution in original post

7 Replies
JustinColville
Esri Contributor

@LucasNeal 

item delete has a "permanent" parameter available (https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#item).

"Optional boolean. Available in ArcGIS Online, setting to True will permanently delete the item rather than sending it to the recycle bin."

This might be what you are looking for?

LucasNeal
New Contributor II

Thank you Justin you are a life saver!

0 Kudos
MikeVolz
New Contributor III

Maybe there is a programmatic way to toggle off the AGOL Recycle bin while you are running your scripts?

Tom_Laue
New Contributor III

@JustinColville 

Has anyone successfully been able to permanently delete an AGOL item via Python AFTER ESRI added the recycle bin?

 

from arcgis.gis import GIS
gis = GIS("home")

item_id='767ff8fe699047d7bc0e74c0f15a63a4' #this is the service_ID of the hosted feature layer to delete

itemToDelete = gis.content.get(item_id)
itemToDelete.delete(permanent=True)

 

 

Running this code in AGOL Notebooks as well as Python 3.9.16 on my computer with Pro 3.1.2 I get the following error message:

 

 

TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_19/3146111176.py in <cell line: 7>()
      5 
      6 itemToDelete = gis.content.get(item_id)
----> 7 itemToDelete.delete(permanent=True)

TypeError: delete() got an unexpected keyword argument 'permanent'

 

0 Kudos
GregHorne
New Contributor III

I too am seeing: TypeError: delete() got an unexpected keyword argument 'permanent'

I had Python that was deleting items on AGOL and then copying up to AGOL updated like named items.  After we turned on the recycle bin the copying up wasn't working anymore since the like named items were in the Recycle Bin.  Found this thread but now seeing issues with the 'permanent' option.

I am retrieving the item by name but have also retrieved it by item ID with the same results.

Python 3.9.18   ArcGIS Pro 3.2.0

0 Kudos
MappyIan
Occasional Contributor III

I was getting the same error trying to use item.delete(permanent=True) in an ArcGIS Notebook @GregHorne@Tom_Laue.  But once I updated my Notebook to use the latest runtime it worked fine and the item is deleted permanently without going anywhere near the recycle bin.  The Notebook Runtime setting is on the Setting page of the item in AGOL, I just set it to the most recent version:

MappyIan_0-1721728017908.png

Hope this helps.

GregHorne
New Contributor III

@Tom_Laue  For executing from Python on the desktop, it looks like the issue is that one needs to use arcgis (ArcGIS API for Python) v 2.3.0 which comes with ArcGIS Pro v3.3.0.  I tried using Pro v3.1 and v3.2 which comes  with arcgis v2.2.0.1.

I am not familiar with cloning Python environments but I did try that with Pro v3.1 and v3.2 and then attempted to update the arcgis package but that did not help.  It never upgraded out of v2.2.0.x

0 Kudos