Unable to delete feature class with arcpy.Delete_management()

1218
3
02-15-2022 12:21 AM
LuisDelValle
New Contributor II

Hi,

I have a feature class called DeviceView that I need to delete and recreate. The logic that I use to delete feature classes is:

def delete(fc):
    if arcpy.Exists(fc):
        print(f"{fc} exists, deleting...", end="")
        try:
            arcpy.Delete_management(fc)
            print("successful")
        except Exception as e:
            print(f"unable to delete, reason: {e}")
    else:
        print(f"{fc} doesn't exist, skipping...")

 When I execute the logic above, I get the following log in the console:

DeviceView exists, deleting...successful

 Which indicates to me that the operation was 'successful' and no exception was generated while attempting to delete it.

However, the View still exists in the database after executing that logic and a subsequent scripts fails because of this.

I know the delete logic works for other feature classes (not views) which are effectively deleted from the DB.

Thanks in advance for any advise that could give an insight into this issue.

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

Delete (Data Management)—ArcGIS Pro | Documentation

It works on objects on disk or those created in the memory workspace (not just in memory)

Write geoprocessing output to memory—ArcGIS Pro | Documentation

otherwise it has no effect


... sort of retired...
LuisDelValle
New Contributor II

Thanks Dan, I will have a look at this.

0 Kudos
LuisDelValle
New Contributor II

Thanks again @DanPatterson . After a second look, the reason of this issue turned out to be a rather silly one. In ArcGIS Server Manager, we have these two map services: Device and DeviceView. The second one is pointing to the DB View I'm mentioning in the description of this post. 

I hadn't stopped that service. Once I did that, the script deleted the view from the DB.

Apologies for the rookie mistake 

0 Kudos