AnsweredAssumed Answered

SystemError: error return without exception set & arcpy.da.Editor(workspace)

Question asked by Ursus_arctos on Oct 1, 2019
Latest reply on Oct 10, 2019 by heinrich1223

I would like to create a script tool to loop through feature classes in a versioned Oracle database and replace a specified value within two specific fields (if they do exist). I am quite new to ArcPy so I am sure some of the tasks could have been implemented much more elegant. Below is the code I have written so far. Unfortunately, I stumble upon the following problems:

 

  • In a first approach, I used an UpdateCursor without starting an edit session and everything seemed to work fine. The problem was that changes did not seem to be permanent. I ran the script in a script tool in ArcMap and as soon as I closed the program, all changes were reverted
  • After that, I switched to the da.UpdateCursor as it is much faster. When I run the script in PyScripter, it stops at line 20 ("for row in cursor") with the following error message:

        

         RuntimeError: Objects in this class cannot be updated outside an edit session [owner.example_edit]

                              

  • Next, I tried to implement starting an edit session and I get the generic error message (line 14, "edit.startEditing(False, True)"):

        

        SystemError: error return without exception set

 

I have consulted many forum posts related to this error and have tried many different things. At one point, it even run through but stopped at "edit.stopOperation()" with the same error. Unfortunately, I cannot figure out the exact problem and I am not able to solve it.

 

  • Further, but not so important, ListFeatureClasses() is very slow when I run the script in PyScripter. It takes several minutes to list all feature classes. On the other hand, if I run the same snippet directly in the python console in ArcMap, it takes only a few seconds.

Any kind of help is much appreciated!

 

Cheers

 

 

import arcpy
from arcpy import env
import os

env.workspace = r"G:\aaa\bbb\ccc.sde"
user_old = arcpy.GetParameterAsText(0)
user_new = arcpy.GetParameterAsText(1)
fields = "CREATE_BY", "CHANGE_BY"

fcList = arcpy.ListFeatureClasses("owner.*")
fcList.sort()

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

for fc in fcList:
    if len(arcpy.ListFields(fc,"CREATE_BY"))>0:
        with arcpy.da.UpdateCursor(fc, fields) as cursor:
            for row in cursor:
                if row[0] == "domain" + "\\" + user_old:
                    row[0] = "domain" + "\\" + user_new
                    if row[1]  == "domain" + "\\" + user_old:
                        row[1] = "domain" + "\\" + user_new
                        cursor.updateRow(row)
                        arcpy.AddWarning("field in " + fc + " updated")

edit.stopOperation()
edit.stopEditing(True)

arcpy.AddWarning(user_old + " --> " + user_new + " successfully changed in all feature classes!")

Outcomes