Trouble using arcpy.da.insertCursor() on a registered version. Does anyone have any insight or work arounds?

731
3
04-03-2018 08:53 AM
MiguelTorres1
New Contributor

I have been plugging along quite deligently on a GUI tool that I have posted on here before. This time i am asking about an error I get that seems to occur when i try to use insertRow() along with a registeredVersion of a featureclass.

The script works perfectly fine when it is not operating on a versioned data set, and so I am a little confused about how to proceed.

Error when edit.startEditing(True, False)

workspace already in transaction mode

Error when edit.startEditing(True)

error return without exception set

Here is some code I am using, the input is just a .csv of y,x coordinates.

import arcpy, os f = open(".../swPointTest.txt") lstNodes = f.readlines() try:     edit = arcpy.da.Editor(r"Database Connections\PW_Tax_sql_PW.sde")     edit.startEditing(True, False)     cntr = 0     with arcpy.da.InsertCursor(r"Database Connections\PW_Tax_sql_PW.sde\PW.PW.swNodes",("SHAPE@XY", "ASBUILTID","PROJECTID")) as cur:         for node in lstNodes:             cntr += 1             vals = node.split(",")             latitude = float(vals[0])             longitude = float(vals[1])             ABID = "FTR-" + str(cntr)             PID = float(1354.07)             print("Latitude: " + str(latitude) + " x Longitude: " + str(longitude))             rowValue = [(latitude,longitude),ABID,PID]             print(rowValue)             cur.insertRow(rowValue)             print("Inserted Node")     edit.stopEditing(True) except Exception as e:     print(e.message) finally:     f.close()

Thank you for any insight you may be able to provide.

Just to add, after a little bit of digging i managed to find a thread here about a similar issue has persisted since 10.0. It seems like my issue is related to this one.

0 Kudos
3 Replies
BalajiVeera
Occasional Contributor

For versioned data, we should start Edit session, without UNDO. So first parameter should be False

edit.startEditing(False)   (or)  edit.startEditing(False, False)

And use the startOperation & stopOperation methods on each feature insert.

See the simple example from help document - Editor example 2

Editor—Help | ArcGIS Desktop 

MiguelTorres1
New Contributor

I added your recommended changes but I continue to get the following errors

Editor.startEditing(False)

...

Editor.startOperation()

   > error return without exception set

Editor.startEditing(False, False)

...

Editor.startOperation()

   > workspace already in transaction mode

0 Kudos
BlakeTerhune
MVP Regular Contributor

Here's what I use

edit = arcpy.da.Editor(workspace)
try:
    edit.startEditing(multiuser_mode=True)
    edit.startOperation()
    with arcpy.da.InsertCursor(in_table, field_names) as cursor:
        #
        # do stuff
        #
    edit.stopOperation()
    edit.stopEditing(save_changes=True)
except:
    # Attempt to clean up edit session
    try:
        edit.abortOperation()
        print "operation aborted in except"
        edit.stopEditing(save_changes=False)
        print "edit stopped in except"
    except Exception as otherErr:
        # Handle unexpected error when stopping edit
        print otherErr
        pass
    # Re-raise original exception
    raise
finally:
    del edit‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

You should be able to use Editor in a with statement to do all the cleanup automatically but I can never get it to work on versioned data.

0 Kudos