Opening a dataset prevents version from being deleted

133
1
12-08-2021 03:10 PM
JonathanBailey_LimGeomatics
Occasional Contributor

I've created a Python script that creates a version, opens datasets on it, then attempts to delete the version. If the ArcPy workspace environment variable is set to a workspace pointing to the created version, and if a dataset is opened, it seems impossible to delete the version.

Following is Python code to reproduce:

 

import arcpy

workspace = "<path to .sde file connecting to sde.DEFAULT version>"
edit_version_workspace = "<path to .sde file connecting to sde.DEFAULT version>"
BLOCKS_FEATURE_CLASS = "<block layer>"
DETAIL_TABLE = "<detail table>"

arcpy.management.CreateVersion(workspace, "sde.DEFAULT", "TestVersion", "PROTECTED")
arcpy.env.workspace = edit_version_workspace

blocks_joined_to_details = arcpy.management.AddJoin(BLOCKS_FEATURE_CLASS, "OBJECTID", DETAIL_TABLE, "BLOCKOID", "KEEP_ALL")
del blocks_joined_to_details

arcpy.env.workspace = workspace
arcpy.ClearWorkspaceCache_management(edit_version_workspace)
arcpy.DeleteVersion_management(workspace, "<user>.TestVersion")

 

 

When calling the DeleteVersion_management function, an error is returned:

ERROR 160363: The version is currently in use.
Failed to execute (DeleteVersion).

Commenting out the lines to create the joined dataset and delete it prevent this error from occurring and the version is successfully deleted.

How do I get rid of the reference to the version that's preventing me from deleting it?

Tags (2)
0 Kudos
1 Reply
Mike_I
by Esri Contributor
Esri Contributor

Hello JonathanBailey,

How is this issue going? I was able to run this code successfully with a mock block layer and detail table without the error message.

If you're still having the issue, you could try the arcpy.DisconnectUser() function to disconnect any users accessing the version. Link: DisconnectUser

Cheers,

Mike

Data Management Specialist, Esri Support Services
0 Kudos