Strange Error While Using arcpy.da.UpdateCursor on SDE

02-16-2022 05:55 AM
by Anonymous User
Not applicable

I ran the following code on a gdb target and it worked just fine. Now that I've redirected at an SDE target I am getting an ambiguous error: 



def edit_feature_class(structure_data,workspace):
    fc = "Target Feature"
    fields = ["Target Field"]
    descriptions = structure_data["Target Field"].tolist()
    with arcpy.da.Editor(workspace) as edit:
        with arcpy.da.UpdateCursor(fc, fields) as cursor:
            for row in cursor:
                row[0] = descriptions[i]
                i = i+1



 The error it throws is: with arcpy.da.UpdateCursor(fc, fields) as cursor TypeError Cannot update table


Any help is appreciated, 

Thank you



0 Kudos
5 Replies
Occasional Contributor III

Is "Target Field" really the field name or is it an alias? I think some databases don't allow spaces in the field names....

If the failure is on the updateRow I would add some print or AddMessage statements to dump out descriptions[i] to see which record it is choking on and the contents of the field at that point. 

by Anonymous User
Not applicable

Target Field just a dumby name I'm using for the purposes of the question, the real name is a single word. The failure is on 

with arcpy.da.UpdateCursor(fc, fields) as cursor:


Occasional Contributor III

Another idea is to start removing fields from the list  until is starts working, or try a SearchCursor on that feature class- perhaps with just the ['objectid'] field to start with ( assuming you have  field called that).  

0 Kudos
MVP Esteemed Contributor

fc  ... is that the full path to the featureclass?

fields ... you have confirmed the field names?

as for the cursor, do you have permissions to create one for the source file?

... sort of retired...
0 Kudos
Occasional Contributor III

Hi fellow, 

to be hones I do not trust yet in the implementation of arcpy for the use of objects with the function "with",

I would strongly suggest to go in the direction of the old school and use the methods of the editor object:

startOperation ()
stopOperation ()
abortOperation ()
undoOperation ()
0 Kudos