Hello,
I try to edit the associations table with the REST or GIS API, however I get an error when using deleteFeatures or applyEdits
--> AGS Logs, no additional logs in FINE or VERBOSE mode
SEVERE | 6 nov. 2024, 09:04:23 | An error occurred. |
When doing it programmatically in python, I get this error :
2024-11-06 04:26:20,835 ERROR Unable to complete operation.
Unable to perform applyEdits operation.
An error occurred.
(Error Code: 500) - Traceback (most recent call last):
.....
File "D:\arcgis_enterprise\server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features\layer.py", line 3306, in edit_features
return self._con.post_multipart(path=edit_url, postdata=params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\arcgis_enterprise\server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1270, in post_multipart
return self._handle_response(
^^^^^^^^^^^^^^^^^^^^^^
File "D:\arcgis_enterprise\server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1001, in _handle_response
self._handle_json_error(data["error"], errorcode)
File "D:\arcgis_enterprise\server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1024, in _handle_json_error
raise Exception(errormessage)
Exception: Unable to complete operation.
Unable to perform applyEdits operation.
An error occurred.
(Error Code: 500)
Is it possible to edit this table through the REST or GIS API ?
It should work, and when it fails I would expect something a bit more meaningful than a 500 errors. This implies something deeper is going wrong. What version/patch of enterprise are you on, and is there a crash dump that corresponds to this?
Can you post the script you're using for Python? I'm assuming that you're doing this against default and that you're starting a read then edit operation, but a script will be more informative. Having access to your script also lets me test it out on my server 😁
Hi Robert
this was the code I was using :
def DeleteFeatures(featureLayer, oids: list, gdb_version: str = VERSION) -> None:
if len(oids) == 1:
result = featureLayer.edit_features(deletes=oids, gdb_version=gdb_version)
AnalyzeEditResults(result)
else:
maxRecordCount = featureLayer.properties.maxRecordCount
_oids = list(_divideChunks(oids, maxRecordCount))
for k, oidsChunk in enumerate(_oids, start=1):
logger.debug(f"chunk {k} sur {len(_oids)}")
result = featureLayer.edit_features(deletes=oidsChunk, gdb_version=gdb_version)
AnalyzeEditResults(result)
However, with your helpful advice and this link (https://support.esri.com/en-us/knowledge-base/how-to-edit-branch-versioned-feature-layers-using-the-...), I changed to :
def DeleteFeatures(featureLayer, oids: list, gdb_version: str = VERSION,
version_management_server_url: str = VERSIONMANAGEMENT) -> None:
try:
portal, featureServerItem = _MakeConnectionToService()
vms = _getVersion(version_management_server_url, portal)
with vms.get(gdb_version, "read") as version:
version.start_editing()
if len(oids) == 1:
result = featureLayer.edit_features(deletes=oids)
print("success")
AnalyzeEditResults(result)
else:
maxRecordCount = featureLayer.properties.maxRecordCount
_oids = list(_divideChunks(oids, maxRecordCount))
for k, oidsChunk in enumerate(_oids, start=1):
logger.debug(f"chunk {k} sur {len(_oids)}")
# sessionId = "{" + f"{uuid.uuid4()}" + "}"
# result = featureLayer.edit_features(deletes=oidsChunk, gdb_version=gdb_version, session_id=sessionId)
result = featureLayer.edit_features(deletes=oidsChunk)
AnalyzeEditResults(result)
version.stop_editing(save=True)
version.mode = None
except Exception as err:
print("Error: {0}".format(err))
Now I have the following error :
Error: The operation is not supported against the default version.
(Error Code: 0)
It may be because the Default version is protected... but my user have version management capabilities and is admin.
I'll test this out on my end, here are my initial observations:
Try using the applyEdits method on the service and pass in the layer id and global id of the feature you want to delete.
1- yes, my user has the built-in admin account
2- I can't find how to get the Asso layer from the Version object... Listing all version.layers layers does not return the 500001 layer...
3- trying this
featureLayer.delete_features(deletes=oids, gdb_version=gdb_version, rollback_on_failure=True)
results in the error :
ERROR: 2024-11-07 10:53:05,333 - ERROR - Error: Unable to complete operation.
Unable to perform applyEdits operation.
An error occurred.
(Error Code: 500)
Finally, when applying edits directly on the service, it results in a success... but it seems to have no effect because I can still find the globalId in the same version after the applyEdit...
[ { "id": 500001, "deleteResults": [ { "globalId": "{D75D19CD-99E7-415C-B866-006A5E113720}", "success": true } ] } ]
[EDIT] : it IS working when deleting from the service, in Default or Named versions. However, I can still query the feature, but the Status field changed from 0 to 33, probably indicating that the row has been deleted.
[EDIT 2] Reading the doc (https://pro.arcgis.com/en/pro-app/latest/help/data/utility-network/associations-table.htm#GUID-DF91C...) I am not sure how to interpret the 33 Status value...
@PierreloupDucroix Deleting an association, through rest or the user interface, only logically deletes the association. Once you validate the edit, updating the system tables, the association will be physically deleted from the version. 33 = 32 + 1 = The "To feature" in the association is dirty and the association is deleted. This means when the association was logically deleted we placed a dirty area on the "to object" so it could be validated using the map.
After validating the dirty area, the association is now deleted, thank you.
Do you know any way to apply edits on the service with the ArcGIS API for Python ? Or will I have to do REST requests like I did manually ?
I haven't had a chance to test out using the FeatureLayer object yet, but you could try doing that by global ID or object ID.
If you can't find a path forward via the ArcGIS API for Python, but can produce a correct result using the REST endpoint directly, I'd recommend you log a case with support. We could either expose the appropriate ArcGIS API for Python object, or determine why directly editing the layer doesn't work.
I rewrote my code, and I am now sure that there is a bug with Association table editing with the ArcGIS API for Python.
My code works well when passing a standard featureLayer or Table, but not when passing the UN Asso Table.
It gives me an Error : this operation is not allowed while editing (Error Code: 500)
I will log a case with the support.
Regards