Re: Objects in this class cannot be updated outside an edit session

211
3
03-02-2021 01:14 AM
ShahriarRahman
New Contributor III

Hi All,

I have defined the workspace, started and stopped the edit session, but afterwards, I am getting the Runtime Error (Objects in this class cannot be updated outside an edit session). The layer "CGD. ROAD_LOCATIONS" is versioned.

……….Script (part)……………..

arcpy.env.workspace = r"\\Pas215q4\User Connection\GS-0001.database.windows.net(1).sde"

edit = arcpy.da.Editor(arcpy.env.workspace)

if (edit.isEditing!='True'):

    edit.startEditing(True, True)

    edit.startOperation()                   

   field = ['SECTION_ID']

   found_values = defaultdict(set)                   

   with arcpy.da.UpdateCursor("CGD.ROAD_LOCATIONS", field, "[OBJECTID] > 944861") as cursor:

       for row in cursor:

         for i, column in enumerate(field):

           if row[i] in found_values[column]:

            cursor.deleteRow()

            break

         else:

            for column, value in zip(field, row):

            found_values[column].add(value)

   edit.stopOperation()

   edit.stopEditing(True)

................................

When running this it breaks in (“for row in cursor”), and I am getting the following error message,

………..Error message…………

Traceback (most recent call last):

  File "P:\Create_Assets.py", line 152, in <module>

    main()

  File " P:\Create_Assets.py", line 52, in main

    for row in cursor:

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

No issue with the indentation, maybe I have missed the proper indent here as I am typing it manually. No issue with the script while running from the admin account, but other user accounts is experiencing the run-time issue.

Great to have your suggestions on how to solve this issue please.

Kind regards,

Shahriar

0 Kudos
3 Replies
JoshuaBixby
MVP Esteemed Contributor

The following,

No issue with the script while running from the admin account, but other user accounts is experiencing the run-time issue.

strongly indicates there is a permissions issue happening, whether by design or a defect. 

If non-admin users try the workflow manually in the application, do they get the same error?

0 Kudos
ShahriarRahman
New Contributor III

Hi Joshua,

If non-admin users try the workflow manually in the application, do they get the same error? Yes.

The users have full access to the .sde feature class ("CGD.ROAD_LOCATIONS") and versioning completed. So, I believe there is little chance of permission issue. Do you think there might be some other reasons?

Thanks,

 

Shahriar

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If it works for admin users and not regular users whether using ArcPy or the GUI, it is permissions related.  The question is whether there is a workflow issue or defect.  Without knowing a bit more about the overall workflow, e.g., versioning steps before you get to the functional code part above, I can't offer much on that front.  I would suggest you have your DBA look at the database logs because there may be errors showing up there that could point you in the right direction.

 

0 Kudos