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?
What is the full traceback of the error?
The full error is:
Traceback (most recent call last):
File "D:\scheduled_tasks\ProjectFolder\WCO_dataPull_editTest.py", line 41, in CreateOperatorDatabase
with arcpy.da.Editor(os.path.dirname(gisweb_wco), multiuser_mode=True):
TypeError: function takes at most 1 argument (2 given)
The full Traceback for the original error is:
Traceback (most recent call last):
File "D:\scheduled_tasks\WildlifeControlOperators\WCO_dataPull.py", line 111, in CreateOperatorDatabase
arcpy.management.DeleteFeatures(gisweb_wco)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 4241, in DeleteFeatures
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 4238, in DeleteFeatures
retval = convertArcObjectToPythonObject(gp.DeleteFeatures_management(*gp_fixargs((in_features,), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 160250: Objects in this class cannot be updated outside an edit session
Failed to execute (DeleteFeatures).
What version of ArcGIS Pro are you using? Looks like the 2.9 version does not have support for the multiuser_mode parameter.
That could be the issue. The server that I need to run the script from currently has 2.9.3 installed. Thanks for catching that, most of our servers have been updated to 3x so I just assumed that this server had been updated as well.
I ran the script from another server that has version 3.1.2 installed and although I am not getting the 'argument' error any more, I do still get the '...outside an edit session' error. I am fairly certain that this is not an issue with the script, but an admin issue with the .sde or maybe the feature dataset that contains the FC. I notified the database administrator of the issue and if they can't fix it on their end I'll just open a ticket.
Just a quick follow up, but I have confirmed it's not a script issue because the Delete tool doesn't run from ArcPro on the dataset either. My DB Administrator mentioned that is seems the issue was first documented after the ArcPro 3.0 update which makes me think it is a bug. I don't think this is a 'Editing' issue at all (hence the error shouldn't be taken at face value), but probably more of an 'access' problem. I will post if we find a solution, but would be interested if any one else has encountered a similar issue.
I was encountering the same issue, although not with in a versioned Enterprise GDB, but in a local FGDB. In the end I realized that it was a licensing issue: I was testing with a basic account on a database created with the standard account containing relationships.