I am having an issue where I cannot delete a version because it is said to still be in use, but this error only arises when I use the script from an ArcGIS Tool in the Toolbox. When I run the script from an outside IDE, or even the same commands from the python window, it finishes without error.
The general process is:
1) create a new version "Child"
2) Loop of feature classes:
2.1) create feature layer
2.2) change to version "Child"
2.3) various queries etc
2.4) copy feature layer
2.5) change to version Default
3) run arcpy.ClearWorkspaceCache_management() [updated]
4) delete version "Child" --- arcpy.DeleteVersion_management(sde_database, "username".Child)
The error returned by the tool dialogue is:
Executing: DeleteVersion "/path/connectionfile.sde" "username".Child
Start Time: Thu Feb 19 13:12:24 2015
ERROR 999999: Error executing function.
The version is currently in use. ["username".Child]
Failed to execute (DeleteVersion).
At this point I will go to the Version Manager to delete the Child version manually and I get the following error:
Could not delete version "username".Child.
[An event was unable to invoke any of the subscribers (Exception from
HResult: 0x80040201)]
If I close and reopen ArcMap I can then delete the version. Does anyone have an idea what might be causing this and how to resolve it?