Python Transaction Runtime Error – Code Runtime Error: In Transaction Mode Using ArcGIS Pro

arcgis-proarcpycursorruntimeerror

arcpy.env.workspace = "Project Path"

feature1 = arcpy.env.workspace+'TableWithEstimates'
feature2 = arcpy.env.workspace+'TableToJoin'

interval = 7

arcpy.CreateTable_management(arcpy.env.workspace,'JustEstimates')
arcpy.management.AddField('JustEstimates', 'FID', 'TEXT')
arcpy.management.AddField('JustEstimates', 'PRICEEST', 'FLOAT')

cur = arcpy.da.UpdateCursor(feature1, ['IN_FID','ESTPRICE'])
cur2 = arcpy.da.InsertCursor('JustEstimates', ['FID','PRICEEST'])

for row in cur:
    if row[0] % interval == 0:
        cur2.insertRow(row)
    else:
        pass
        
del cur, cur2, row

This is an excerpt of the code I am running. The purpose of this is stretch is to take a previously created table and take every seventh row out of it to get the estimates I am looking for. I am going to join this with some other data generated, but need this to work first to match estimate data to another data source.

In Arc's Jupyter platform, I keep getting this error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
In  [2]:
Line 19:    cur2.insertRow(row)

RuntimeError: workspace already in transaction mode
---------------------------------------------------------------------------

This makes no sense as other soultions dealing with problem point to it as a versioning issue. I imported all of this data into a default template from emailed files that also required some jigging. The data should not be versioned since I was the one who created it in ArcGIS Pro.

What could be causing this?

At some point, I did enter this line in a previous Jupyter block.

edit = arcpy.da.Editor(arcpy.env.workspace)
edit.startEditing(False, False)

This addressed the failure of ArcGIS Pro to make the table using the arcpy.CreateTable_management() function. I patched one hole and now I have another and this one is not unpatching.

Best Answer

Maybe the updatecursor is blocking the insertcursor from inserting new rows? You dont seem to use it for updating records so you might aswell replace da.UpdateCursor with da.SearchCursor:

...

cur2 = arcpy.da.InsertCursor('JustEstimates', ['FID','PRICEEST'])

with arcpy.da.SearchCursor(feature1, ['IN_FID','ESTPRICE']) as cur:
    for row in cur:
        if row[0] % interval == 0:
            cur2.insertRow(row)
        
del cur2
Related Question