RuntimeError: start edit session

1389
3
Jump to solution
05-15-2019 01:20 PM
BrandonZaitz
New Contributor III

For some reason when i try and start and stop an edit session the stop.Editing(True) does not work because it appears that an edit session was never started. See code snippet below:

workspace = os.path.dirname(shl_fc)

edit = arcpy.da.Editor(workspace)

edit.startEditing()
arcpy.AddMessage(isEditing)
edit.startOperation()

# Update SHL Geometry
with arcpy.da.UpdateCursor(shl_fc,[shl_dsu_field_name,shl_well_num_field_name,'SHAPE@XY']) as shl_updatecursor:
for feature in shl_updatecursor:
if dsu_name in feature[0] and well_num in feature[1]:
projected_shl_coordinates = ProjectCoordinates(float(shl_coordinates[0]),float(shl_coordinates[1]),shl_coords_spatial_ref,shl_fc_spatial_ref)
newrow = []
newrow.append(feature[0])
newrow.append(feature[1])
newrow.append(projected_shl_coordinates)
shl_updatecursor.updateRow(newrow)

edit.stopOperation()

edit.stopEditing(True)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Update: I added an 'AddMessage' statement to return the boolean value of '.isEditing' and it returns True.

Update 2: Adding the 'isEditing' before the '.startEditing' returns False.

0 Kudos
1 Solution

Accepted Solutions
BrandonZaitz
New Contributor III

The error it was returning is in the title of my post. "RuntimeError: start edit session". I solved the problem myself. Was running this script via a Toolbox in ArcGIS Pro and the layers were marked as editable in the contents. This prevent the script from updating the feature class. However, just an FYI, having the box checked next to a layer in ArcGIS Pro in the 'List by Editing' tab of the 'Contents' does not cause '.isEditing' to return 'True' but it does prevent an update cursor from updating a feature and prevents starting and stopping edit sessions from working properly.

View solution in original post

3 Replies
RandyBurton
MVP Regular Contributor

It looks like your edit session is being set-up correctly.  However, I do not think you are using the UpdateCursor correctly - specifically lines 14-18 in your code.  I don't think you are actually changing anything.

If the code is part of a custom script tool or Python toolbox, you may not be seeing any messages or errors generated by the update cursor.  Since the AddMessage is working, you might try adding this code immediately using GetMessages following the update cursor to display any messages from the update cursor:

            arcpy.AddMessage(arcpy.GetMessages())‍‍
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Does not work?  Can you elaborate?  Are you getting an error?  If so, what is the error and traceback of the error.  If you are getting unexpected results, what are you getting vs what you expect?

0 Kudos
BrandonZaitz
New Contributor III

The error it was returning is in the title of my post. "RuntimeError: start edit session". I solved the problem myself. Was running this script via a Toolbox in ArcGIS Pro and the layers were marked as editable in the contents. This prevent the script from updating the feature class. However, just an FYI, having the box checked next to a layer in ArcGIS Pro in the 'List by Editing' tab of the 'Contents' does not cause '.isEditing' to return 'True' but it does prevent an update cursor from updating a feature and prevents starting and stopping edit sessions from working properly.

View solution in original post