There are are numerous post on this error, but I can't seem to find a solution for myself. We have a versioned sde and need to add new fields to some of our feature classes and populate them with an updateCursor.
import arcpy print('Script Started') arcpy.env.workspace = r"Database Connections\Connection to gisprd.sde" edit = arcpy.da.Editor(arcpy.env.workspace) edit.startEditing(True, False) fcNames = [ "Transformer", "DynamicProtectiveDevice", "Switch", "BulkDeliveryPoint", "BusBar", "CableFault", "ConduitSystem", "Fuse", "NetworkProtector", "OpenPoint", "OverheadPrimaryLine", "OverheadSecondaryLine", "Riser", "ServicePoint", "SupportStructure", "SurfaceStructure", "UndergroundPrimaryLine", "UndergroundSecondaryLine", "UndergroundStructure", "VoltageRegulator", "WireChange" ] fcs = arcpy.ListFeatureClasses("","","LIPA.Distribution") print('Starting loop') for fc in fcs: # get feature class name name = arcpy.Describe(fc).baseName[5:] print(name) path = arcpy.Describe(fc).catalogPath # only do to the features listed above if name in fcNames: # Add field to store static object ids arcpy.AddField_management(path,'ORIG_OID', 'LONG') oid =  # initalize empty to store objectids idx = 0 # initalzie empty index counter to add correct objectid to new field for static oid # Use cursors to get actual objectids for features of interest print('Starting Search') with arcpy.da.SearchCursor(path, ('OBJECTID',)) as cursor: for row in cursor: oid.append(row) print('Search finished, starting update') # Iterate update cursor over new field edit.startOperation() with arcpy.da.UpdateCursor(path, ('ORIG_OID',)) as upCursor: # for each row update with the correct object id and then increment the counter index for row in upCursor: row = oid[idx] idx += 1 upCursor.updateRow(row) print('Finished update') edit.stopOperation() del cursor del upCursor edit.stopEditing(True) del edit
I got the following traceback:
for row in upCursor: RuntimeError: workspace already in transaction mode
Can anyone assist?
links of similar questions:
- The above two are both trying to work in different versions. We only do stuff like this on weekends after all the work is done for the week, everything has been reconciled and compressed (database is at state 0; not worried about versions).
- This one seems to indicate that error means an edit session is not open? So maybe I am setting up the editor wrong?