I am trying to Delete, then Append data to a feature class in a versioned Enterprise GDB using a Python script (which is scheduled). I have run this same script before without issue and have other scripts running to update datasets on the same GDB that run without issue as well. I noticed that one of my scripts failed with the Error:
ERROR 160250: Objects in this class cannot be updated outside an edit session
Failed to execute (DeleteFeatures).
Not sure if the is due to a setting that was changed on the feature class (which I do not administer and have no control over), but in response the the error, I tried to use the Editor class and start an editing session on the feature class before trying to Delete the records. Here is my code:
# Environment settings and global variables print ("Setting workspace and defining global variables\n")
workFolder = r"\\server\\Scheduled_Tasks\\ProjectFolder"
logging.info("Setting workspace and defining global variables\n")
TempDB = "Temp.gdb"
TempWS = os.path.join(workFolder, TempDB)
gis_sde = '\\\\tasksFolder\\DB_connections\\gis_gdb.sde'
GISDB = os.path.join(gis_sde, "gis_gdb.Feature_dataset")
def CreateOperatorDatabase():
try:
WCO_merc = os.path.join(TempWS, "WCO_merc")
gisweb_wco = os.path.join(GISDB, "gis_gdb.point_featureClass")
with arcpy.da.Editor(os.path.dirname(gisweb_wco), multiuser_mode=True):
arcpy.management.DeleteFeatures(gisweb_wco)
arcpy.management.Append(WCO_merc, gisweb_wco, "NO_TEST","","")
except: print("Failed to process trapper data\n") logging.exception("Failed
to process trapper data\n")
When I run the code I get the error "TypeError: function takes at most 1 argument (2 given)"
Now I am confused because in the documentation it clearly states that the Editor class takes one required argument and one optional argument (and both are needed if editing in a versioned Enterprise GDB).
Documentation: https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/editor.html
Editor (workspace, {multiuser_mode})| Parameter | Explanation | Data Type |
workspace | Path to the workspace to edit. The editor can edit only one workspace at a time. | String |
multiuser_mode | When edits will be performed on versioned data, set this to True; otherwise, set it to False. Only use with enterprise geodatabases. (The default value is True) | Boolean |
Example from doc:
new_students = 'C:/projects/Portland/Portland.sde/ptld.main.students_new2022'
students = 'C:/projects/Portland/Portland.sde/ptld.main.students'
# Start an edit session. Provide the workspace being acted on
# and with sde specify if data is edited in multiuser_mode.
with arcpy.da.Editor(os.path.dirname(students), multiuser_mode=True):
# If all 3 edit operations run successfully without error
# upon exiting this code block the edits will be applied to the data
arcpy.management.CalculateField(new_students , 'arrived', '2022')
arcpy.management.Append(new_students, students)
arcpy.management.CalculateField(students, "active", True)
Can any one tell me what I am missing?