The KEY_FIELD is defined, that was just an incomplete snippet of the code. Here is some example code with error message:
>>> p = r'D:\_RE_MAKE_TEST\eiu.gdb\albers\pre' # belongs to pre_Topology
>>> UPDATE_FIELD = ["ERROR"]
>>> features = p
>>> with arcpy.da.UpdateCursor (features, UPDATE_FIELD) as cursor:
... for row in cursor:
... x = row
...
Runtime error
Traceback (most recent call last):
File "<string>", line 2, in <module>
RuntimeError: Objects in this class cannot be updated outside an edit session
>>>
I think I have found a solution. If I do the update cursor inside an edit session it works. Which is a bit messy but it works. Not having used this approach before does this code look alright?
def update_error_field_EDIT (features, UPDATE_FIELD, error):
fds = os.path.dirname (features)
assert "FeatureDataset" == arcpy.Describe(fds).dataType
gdb = os.path.dirname (fds)
assert is_geodatabase (gdb)
edit = arcpy.da.Editor (gdb)
edit.startEditing (False, False)
edit.startOperation ()
update_error_field (features, UPDATE_FIELD, error)
edit.stopOperation ()
edit.stopEditing (True)
del edit
return