can't edit row with arcpy.da.updatecursor in arcmap

4680
4
Jump to solution
03-13-2016 10:29 PM
BillRichards
New Contributor II

I am at a loss! After hours of searching and testing, in Arcmap (10.3)  I simpy can't get beyond this error:

RuntimeError: Objects in this class cannot be updated outside an edit session [ContactsAndFaults]

while attempting to open an UpdateCursor. The feature class is in a personal database and I am able to add a field, but not use the following:

uid = fc + "Somestring"
with arcpy.da.UpdateCursor("C:\\arcmaptest\\Paddock_Valley_Reservoir.mdb\\" + fc, ("OID@", uid)) as cursor:
     for row in cursor:
          row[1] = fc + "-" + anotherstring+ "-" + row[0]  # basically append the OBJECTID to the uid string
          cursor.updateRow(row)

Any suggestions?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ModyBuchbinder
Esri Regular Contributor

Hi

If your data is part of something like topology or network it cannot be update without edit session.

You can start edit in ArcMap and then try to run the script.

In general you should try to move from mdb to gdb.

Have fun

View solution in original post

4 Replies
ModyBuchbinder
Esri Regular Contributor

Hi

If your data is part of something like topology or network it cannot be update without edit session.

You can start edit in ArcMap and then try to run the script.

In general you should try to move from mdb to gdb.

Have fun

NeilAyres
MVP Frequent Contributor

Or wrap your update cursor in something like this :

# open an editor session
edit = arcpy.da.Editor(os.path.dirname(outputDiff)) # dirname of the fc is the db name
edit.startEditing(False, False) # check these setting for your environment
edit.startOperation()
# do the update loop
# stop editing
edit.stopOperation()
edit.stopEditing(True)
BillRichards
New Contributor II

Yes,

Opening the edit session was required as some of the feature classes (tables) in the personal database are participating in topologies. Thanks for the suggestion!

0 Kudos
BenjaminMittler
Occasional Contributor III

I would recommend converting your personal geodatabase to a file geodatabase.

0 Kudos