da.editor throwing error

3228
5
09-16-2014 02:08 PM
ChrisMathers
Occasional Contributor III

Getting an error when I run this. Cant see why. Any ideas?

with arcpy.da.Editor(r"D:\GIS-DATA\bay-arcgis-pro@sde@sde.sde"):

    with arcpy.da.UpdateCursor(production_parcels,'OID@') as cursor:

                    for row in cursor:

                        if row[0] in delete_OIDs:

                            cursor.deleteRow()                      

    with arcpy.da.UpdateCursor(staging_parcels,'OID@') as cursor:

                    for row in cursor:

                        if row[0] not in append_OIDs:

                            cursor.deleteRow()              

    arcpy.Append_management(staging_parcels,production_parcels,'NO_TEST')

Traceback (most recent call last):

** IDLE Internal Exception:

  File "D:\Python27\ArcGISx6410.1\lib\idlelib\run.py", line 93, in main

    seq, request = rpc.request_queue.get(block=True, timeout=0.05)

  File "D:\Python27\ArcGISx6410.1\lib\Queue.py", line 177, in get

    self.not_empty.wait(remaining)

  File "D:\Python27\ArcGISx6410.1\lib\threading.py", line 262, in wait

    delay = min(delay * 2, remaining, .05)

RuntimeError: start edit session

0 Kudos
5 Replies
AndrewOrtego
New Contributor III

Hi Chris,

It looks like there's an issue with the first line-- the 'with' statement is having trouble starting the edit session.

Are you positive that the script has access to the SDE connection you've specified? Is your raw string correct? Try opening up ArcCatalog and getting the properties of that SDE connection. This will verify that you have permission to access that location, as well as provide you with the string needed for connecting to the SDE via Python.

0 Kudos
ChrisMathers
Occasional Contributor III

Unfortunately that string is correct. The problem seems to be that the session doesn't seem to be starting properly.

>>> arcpy.env.workspace = r'D:\GIS-DATA\bay-arcgis-pro@sde@sde.sde'

>>> def e():

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

    edit.startEditing(True,True)

    print 1

    edit.startOperation()

    print 2

    with arcpy.da.UpdateCursor(production_parcels,'OID@') as cursor:

                    for row in cursor:

                        if row[0] in delete_OIDs:

                            cursor.deleteRow()

    print 3

    with arcpy.da.UpdateCursor(staging_parcels,'OID@') as cursor:

                    for row in cursor:

                        if row[0] not in append_OIDs:

                            cursor.deleteRow()

    print 4

    arcpy.Append_management(staging_parcels,production_parcels,'NO_TEST')

    print 5

    edit.stopOperation()

    print 6

    edit.stopEditing(True)

   

>>> e()

1

2

Traceback (most recent call last):

  File "<pyshell#29>", line 1, in <module>

    e()

  File "<pyshell#28>", line 8, in e

    for row in cursor:

RuntimeError: Objects in this class cannot be updated outside an edit session [sde.SDE.Parcels]

>>>

0 Kudos
curtvprice
MVP Esteemed Contributor

I have no expertise with ArcSDE, but are you sure you may not get better performance anyway by doing a selection on a layer and using the Delete Rows tool - which would do the row deletes at the arc objects level? You can create a sql expression like this:

delete_list = ",".join([str(k) for k in delete_OIDs])

where = "OBJECTID IN ({})".format(delete_list)

0 Kudos
ChrisMathers
Occasional Contributor III

My problem is that I have to delete based on a list of OIDs and in one list there will be around 4000 and the other will be around 117100. The SQL statement that the select tool takes cant be that long so I have to do it in cycles. That is a work around but isn't doesn't resolve the underlying issue here.

ChrisMathers
Occasional Contributor III

Had time to poke at this some more and from a run of exactly the code above run on a 10.2 install got an error that I was trying to edit a closed state. Never a dull moment.

EDIT: Worked at 10.2 after a compress cleared most of the states from the state lineage in the database. Ill try on the 10.1 install where this will run as a scheduled task and update.

EDIT-2: Looks like it was a database state hang up. Works fine now and is faster than making a selection and then deleting the selection.

0 Kudos