I recieved this error:

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

while runnng this code:

# import modules 

import arcpy 
import random
from arcpy import env
import arceditor

arcpy.env.overwriteOutput = True  

arcpy.env.workspace = r"N:\Monument_Mapping_Piedmont\Monuments.gdb"

# creat variables for table and feature class

monDoc = r"N:\Monument_Mapping_Piedmont\Monuments.gdb\MonumentDocument"
monFC = r"N:\Monument_Mapping_Piedmont\Monuments.gdb\Monuments"

# add fields to table and feature class

arcpy.AddField_management(monFC, "QAQC", "SHORT")

# randomly select 10% of records in monument doc table

unIDlst = []
with arcpy.da.SearchCursor(monDoc, "UniqueID") as cursor:
    for row in cursor:

unIDset = set(unIDlst)

docCount = len(unIDset)

sampSize = int(docCount * .1) 

ranDocs = random.sample(list(unIDset), k = sampSize)

monIDlst = []
with arcpy.da.SearchCursor(monDoc, ["MonumentID", "UniqueID"]) as cursor:
    for row in cursor:
        if row[1] in ranDocs:

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

monIDset = set(monIDlst)
with arcpy.da.UpdateCursor(monFC, ["MonumentID", "QAQC"]) as cursor:
    for row in cursor:
        if row[0] in monIDset:
            row[1] = 1


print "Done"

I didn't think I need to have an edit session, but even then I'm still getting this error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.