Select to view content in your preferred language

arcpy.da.Editor(sde_workspace) yields a Workspace Operation object instead of an Editor

42
7
Jump to solution
7 hours ago
RogerDunnGIS
Occasional Contributor II

My Pro project contains an sde connection file called Knight.sde.  I am programming in a Notebook.  When I call arcpy.Describe on "Knight.sde" it shows me that it is indeed a Workspace and provides the full path to the file.  However, the following code yields the following error:

 

with arcpy.da.Editor("Knight.sde") as eddie:
  eddie.startEditing(True, True)
  try:
    eddie.startOperation()
    try:
        with arcpy.da.UpdateCursor("Feature Class") as u_cursor:
          for row in u_cursor:
            # some operation
        eddie.stopOperation()
        eddie.stopEditing(True)
    except:
      eddie.abortOperation()
      if "row" in locals():
        print(row)
      raise
  except:
    eddie.stopEditing(False)
    raise

 

 

AttributeError                            Traceback (most recent call last)
In  [65]:
Line 2:     eddie.startEditing(True, True)
AttributeError: 'Workspace Operation object' object has no attribute 'startEditing'
 

If I print eddie's type in another cell, it shows 'Workspace Operation object' instead of any kind of editor object.  I am totally perplexed, as this pattern of programming has worked in the past.  I have tried a number of different parameters to the arcpy.da.Editor constructor and they all yield 'cannot open workspace' errors so I know that "Knight.sde" is the right thing to pass as an argument.  Why does my Editor constructor give me a weird Workspace Operation object instead?  It's like asking someone for an apple and getting a pinecone instead.

I am using ArcGIS Pro 3.3.1, the latest version available at this time.  I use an enterprise geodatabase on Microsoft SQL Server 2019 that is also the latest version of Esri's geodatabase format at this time, 11.3.0.52636.  I'm using the default Python environment that comes with Pro.

0 Kudos
1 Solution

Accepted Solutions
AlfredBaldenweck
MVP Regular Contributor

I think if you're using the 

with arcpy.da.Editor("Knight.sde") as eddie:

 construction, you don't have to do the whole "Start editing/stop editing" thing; it gets taken care of for you.

Compare the samples on the documentation page: Editor—ArcGIS Pro | Documentation

View solution in original post

7 Replies
RogerDunnGIS
Occasional Contributor II

Also, calling dir(eddie) only yields a list of generic, special methods and properties (the kind that begin and end with two underscores).

0 Kudos
AlfredBaldenweck
MVP Regular Contributor

I think if you're using the 

with arcpy.da.Editor("Knight.sde") as eddie:

 construction, you don't have to do the whole "Start editing/stop editing" thing; it gets taken care of for you.

Compare the samples on the documentation page: Editor—ArcGIS Pro | Documentation

JoshuaBixby
MVP Esteemed Contributor

You are mixing the two patterns of use for Editor—ArcGIS Pro | Documentation.  In addition to the Esri documentation, there are lots of good primers online about the Python with statement and context managers.

RogerDunnGIS
Occasional Contributor II

Thank you.  After looking over the Editor documentation for the n-th time, I noticed __enter__ and __exit__ methods, which do belong to this unknown Workspace Operation object.  I used the optional second parameter of the Editor constructor to indicate that this was a versioned dataset.  Your help will also help me fix two other scripts that broke with the 11.3 update.

0 Kudos
RogerDunnGIS
Occasional Contributor II

Wait, why aren't the results showing in the attribute table, even after a table view refresh, version refresh, and closing and reopening the project?

0 Kudos
RogerDunnGIS
Occasional Contributor II

I don't think the UpdateCursor is updating anything, even after I delete it after the edit session.  Even a SearchCursor yields the old values.

0 Kudos
AlfredBaldenweck
MVP Regular Contributor

Seems like it definitely isn't.

Changes by Update Cursors are notorious for not showing up without a refresh, but since you've done that and also restarted the program...

What's your cursor stuff look like?

0 Kudos