Unable to set Date field to NULL through ApplyEdits endpoint using Python

1247
2
Jump to solution
07-20-2022 02:28 PM
AdamStevens81
New Contributor II

I have a use case where a DATE field needs to be set to NULL under certain circumstances. This is currently not working when sending updates to a branch versioned feature service layer through the ApplyEdits endpoint. This is being performed in a python script sending a POST request to the endpoint.

This is the updates object, as displayed in a debug session:

AdamStevens81_0-1658352245238.png

The error I receive when sending this object:

{'code': 400, 'extendedCode': -2147217395, 'message': 'Unable to complete operation.', 'details': ['Setting of value for LRS_DATE_RETIRE failed.', 'Operation rolled back.', 'Operation rolled back.']}
 
I can successfully update the field manually using the ApplyEdits endpoint with this object:
AdamStevens81_1-1658352401687.png

But I am not able to set this value to NULL through Python, since Python uses None as the NULL keyword and will not recognize the value of NULL. 

Any assistance on this issue will be greatly appreciated!

0 Kudos
2 Solutions

Accepted Solutions
JohnGrayson
Esri Regular Contributor

Are you converting to JSON before sending? What does the JSON representation of your updates object looks like? The REST endpoints only accept JSON and None is not valid in JSON, it needs to be null.

View solution in original post

0 Kudos
AdamStevens81
New Contributor II

Thank you, this did the trick!

I just needed to use json.dumps(updates_object) to create the JSON representation, and this was successfully passed into the applyEdits endpoint.

The object I was sending was formatted as a JSON object, and most of the edit procedures using this formatting have been working, but as a general practice I'll convert all of my JSON-ish objects to actual JSON going forward, to avoid any issues like this.

View solution in original post

0 Kudos
2 Replies
JohnGrayson
Esri Regular Contributor

Are you converting to JSON before sending? What does the JSON representation of your updates object looks like? The REST endpoints only accept JSON and None is not valid in JSON, it needs to be null.

0 Kudos
AdamStevens81
New Contributor II

Thank you, this did the trick!

I just needed to use json.dumps(updates_object) to create the JSON representation, and this was successfully passed into the applyEdits endpoint.

The object I was sending was formatted as a JSON object, and most of the edit procedures using this formatting have been working, but as a general practice I'll convert all of my JSON-ish objects to actual JSON going forward, to avoid any issues like this.

0 Kudos