Quick question - when you call abortOperation() in an edit session -- you still have to stopEditing() afterward right? abortOperation is described as "canceling" an edit, I wasn't sure if stopEditing was necessary. Does what I have below look appropriate?
try: editor = arcpy.da.Editor(db_con) editor.startEditing(False, False) editor.startOperation() with arcpy.da.InsertCursor(gpTestWriteFC, ['SHAPE@', 'FirstName', 'LastName']) as iCursor: for item in insertList: iCursor.insertRow(item) editor.stopOperation() editor.stopEditing(True) except: if editor.isEditing == True: editor.abortOperation() editor.stopEditing(False) fullError = traceback.format_exc() arcpy.AddError(fullError) sys.exit(1)
Solved! Go to Solution.
Then there is the whole 'with' thing
Edit sessions and operations can also be used with Python with statements. The with statements act as context managers and handle the appropriate start, stop, and abort calls for you. The example below highlights the basic structure of the Editor class used with with statements.
and the caveat about doing multiple edit operations. I wouldn't use a try except block since 'with' is supposed to handle failure as well (in that edits will be terminated properly.)
Avoid using a cursor across multiple edit operations. Doing so can result in unexpected behavior and data loss.