Getting the following error below when trying to edit a versioned feature class in an SDE database using a python script tool:
Traceback (most recent call last):
File "L:\Tools\Models\ReconcilePostCalcFields&RecreateVersions.py", line 32, in <module>
for row in cursor:
RuntimeError: workspace already in transaction mode
Code is below:
import arcpy, os
# Set workspace
workspace = "Database Connections\\Connection to gis-prod.sde"
# Set the workspace environment
arcpy.env.workspace = workspace
# Create Version using SDE credentials
arcpy.CreateVersion_management (workspace, "sde.default", "fieldcalcs", "PUBLIC")
# Delcare variables
##versionList = arcpy.ListVersions('Database Connections\\Connection to gis-prod.sde')
inFeatures = "sde_m.SDE.PARCEL"
zip5expression = "!MAIL_ZIP![0:5]"
fl = "fl"
# Change Workspace to access data via OS Auth.
workspace2 = "Database Connections\\SDE_MPL_PROD_OSAUTH.sde"
arcpy.env.workspace = workspace2
# Create Feature Layer for editing
arcpy.MakeFeatureLayer_management (inFeatures, fl)
# Change Version
arcpy.ChangeVersion_management (fl,"TRANSACTIONAL", "sde.fieldcalcs")
# Start an edit session. Must provide the workspace.
edit = arcpy.da.Editor(workspace2)
# Edit session is started without an undo/redo stack for versioned data
# Start an edit operation
# Calculate the MAIL_ZIP5 field
fields = ['MAIL_ZIP5']
with arcpy.da.UpdateCursor(fl, fields) as cursor:
for row in cursor:
row = zip5expression
# Stop the edit operation.
# Stop the edit session and save the changes
If I comment out the UpdateCursor section, the script runs successfully. I have also tried to reconcile, post and delete the child versions before executing the script with the same failure, all locks on the database are shared locks. I thought by versioning and editing, I could get around any locking issues. Any idea how to get the workspace out of transaction mode to allow editing to the child version created in the script?