Problem with UpdateCursor - cannot updagte table

5566
12
09-15-2023 10:55 AM
MarcSeliger
Emerging Contributor

Hi all.

I'm running into a problem with an UpdateCursor in arcpy.
As soon as the script is encountering the UpdateCursor line, it ends with an error "Cannot update table".

I can run a SearchCursor over the feature class without problems, just the UpdateCursor fails every time.

This is the (very simplified) code I'm looking at:

connection = "C:\\Users\\user_name\\AppData\\Roaming\\ESRI\\Desktop10.8\\ArcCatalog\\database.gds\\Utilities (VERSION:dbo.DEFAULT)"
fc = "CV_Valves"
fc_path = f"{connection}\\{fc}"

edit = arcpy.da.Editor(connection)
edit.startEditing(False, True)
edit.startOperation()

with arcpy.da.UpdateCursor(fc_path, "OBJECTID") as cursor:
for row in cursor:
print(row[0])
# cursor.updateRow(row)

edit.stopOperation()
edit.stopEditing(True)

I have the updateRow line commented out for testing purposes, and the actual user_name and db name are replaced by placeholders. I realize that the code is not updating anything, and this is just show the error I'm running into. I'm running Python 3.9

I'm not sure if this has something to do with the SDE I'm connecting to, because the code is simple enough where it shouldn't throw any errors. The same procedure works fine when I connect to an SDE DB on a different system. As I mentioned above, I can run a SearchCursor over the same table without any issues.

Any help or pointers would be greatly appreciated.

Thanks!

Mard

Tags (3)
12 Replies
MarcSeliger
Emerging Contributor

Thanks for your help Alfred, I will give this a try.

0 Kudos
RogerDunnGIS
Frequent Contributor

You said it works in one "system" and not another.  Permission questions have already been asked, but you should also look the edition of ArcGIS Pro that one person has vs. the other.  Perhaps one has a Standard license but the other system uses a Basic license.  That would probably throw such an error.

I think I've received "Cannot update table" when one of the text field values was too large, but that wouldn't explain why one system could do it and the other couldn't.

0 Kudos
chris_del101
Regular Contributor

I had this same issue with InsertCursor, and it was nightmare to debug due to the uselessness of the error message! Thought I'd post in case it helps others.

TypeError: cannot update the table

I had two sets of tables, one in a LocalDatabase, which was a copy made as a File Database by right clicking in Pro and coping the tables, and another in a true RemoteDatabase (SQL server). I had no problems using the local data base, but got this error on the remote - exact same databases just one is for local testing in dev, etc.

My editor was like this:

edit = arcpy.da.Editor(self.sde_path)
edit.startEditing(False, True)
edit.startOperation()
# errored here
with arcpy.da.InsertCursor(table_path, field_names) as cursor:
        ..
edit.stopOperation()
edit.stopEditing(True)

The issue was this line: edit.startEditing(False, True)

The inputs where wrong and did not work with the non-versioned remote DB we had. Docs 

I changed it to edit.startEditing(True, False) and it worked.

Rant: I get that the inputs were wrong for the setup, but how about a runtime error maybe describing the problem here? A generic python stack trace would be far superior to TypeError, when as far as I can see this is not even a TypeError at all! It's a ValueError. So misleading.... 

0 Kudos