Select to view content in your preferred language

How can I test if there was a rollback?

05-12-2021 05:00 PM
New Contributor III

How can I test if there was a rollback?

Where do I find the documentation for Feature Layer's edit_feature method's response?

It's not documented here:


result = layer.edit_features(updates=records, rollback_on_failure=True)

# looking for something like
if result["rollback"]:
    # do something


Unfortunately, the API documentation is incomplete. The official documentation only specifies: "Output: dictionary".

0 Kudos
1 Reply
New Contributor III

After some try and error I got this response:


{'addResults': [{'objectId': 1, 'uniqueId': 1, 'globalId': None, 'success': False, 'error': {'code': 1003, 'description': 'Operation rolled back.'}}, {'objectId': None, 'uniqueId': None, 'globalId': None, 'success': False, 'error': {'code': 1000, 'description': 'String or binary data would be truncated.\r\nThe statement has been terminated.'}}], 'updateResults': [], 'deleteResults': []}


One of the Google result for "1003 Operation rolled back." is:

Seems like the REST API returns 1003 for rollbacks.


Based on above response, I could do something like this:


def is_rolled_back(result):

    for element in result["addResults"]:
        if "error" in element and element["error"]["code"] == 1003:
            return False
    return True

# example with adding records
result = layer.edit_features(add=records, rollback_on_failure=True)

if is_rolled_back(result):
    # do something


However, this is everything else than a satisfying solution. It's solely based on assumptions due to non-existing documentation.

I don't know if the error code 1003 would always be the first element. As I said, all based on assumptions. If it is always the first element, above code can be simplified!

Other ideas and inputs are very welcome and appreciated!

0 Kudos