I have a script that is attempting to edit branch versioned data with the Python API and I am encountering an error I don't really understand.
The essential parts of the script are below:
gis = GIS(portal_url, creds.username, creds.password)
vm_url = test_svc_url.replace('FeatureServer', 'VersionManagementServer')
version_mgr = VersionManager(vm_url, gis)
version = [v for v in version_mgr.all if v.properties['versionName'].lower() == version_name.lower()][0]
addr_pt_fl = version.layers[addr_pt_lyr_id]
# Only return FeatureSet of features that need to be updated
addr_pt_fs = addr_pt_fl.query(where=where, out_fields=['OBJECTID','ADDRAPNID','APNID'], return_geometry=False)
# Code here updates some attributes in the addr_pt_fs FeatureSet to apply to the version
try:
version.mode = 'edit'
version.save_edits = True
result = version.edit(addr_pt_fl, updates=updated_features, rollback_on_failure=True)
version.mode = 'None'
print(result)
except Exception as e:
print(str(e.args))
Now at first I tried using version.start_editing() because it's supposed to set the mode so that when .edit() is called (which checks the mode), it would succeed. I watched my debugger as .start_editing() switched mode to read, then edit, then None. Not sure why that was happening, so I switched to calling the mode setter, which appropriately set the mode to edit. I thus assumed the edit would work. I'm receiving the following error now:
('Unable to complete operation.\nError: Cannot acquire a lock.\n(Error Code: 500)',)I don't know how it wouldn't be able to acquire a lock when this version is private, only I can access it, and there were no locks on it. I even verified the locks list on the VersionManager object and there were none. I also know there were none because I specifically called VersionManager.purge() with my admin credentials to remove locks that were created when I tried both version.mode = 'edit' and version.start_editing().
What's also annoying is that when the VersionManager says there's a lock on my version, I see isLocked, isBeingRead, and isBeingEdited are all True, so I assume there's an exclusive lock on it. However, when I try to run version.mode = 'None' which should terminate the session and release the lock, it does not, saying:
('Object has no schema locks.\n(Error Code: 0)',)so I have to run the admin method I previously described to purge the lock.
Does anyone have any insight into what I'm doing wrong? Thanks in advance
- Jack C