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:
i=0
for row in cursor:
row[0] = descriptions[i]
cursor.updateRow(row)
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
f
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.
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:
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).
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?
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 ()
redoOperation ()
https://gis.stackexchange.com/questions/158594/using-arcpy-da-editor-correctly
Here ( https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/editor.htm )
check the Editor Example 2