Clearing field values by setting them to NULL in the API PATCH method does not clear the field in the database. #5103

Open
opened 2026-02-20 16:29:38 -05:00 by deekerman · 0 comments
Owner

Originally created by @imens-frankd on GitHub (Sep 28, 2023).

While updating data by means of API PATCH method you can't set the value of a field to NULL.
If you set a field to NULL in the json body of the PATCH method then this is ignored.

Expected Behavior

Explicitly setting a field to NULL in the PATCH method should result in setting the field to NULL in the database.

Actual Behavior

The field is not updated in the database.

Possible Fix

The API sets the NULL value correctly on the bean.
The DBManager code however skips properties with NULL value.

'''

include/database/DBManager.php

            if (isset($bean->$field)) {
                $val = from_html($bean->$field);
            } else {
                continue;
            }

'''
I assume this is by design to optimize the SQL queries.
The APi should take this into account and translate the explicit NULL value in the PATCH to an empty string before setting the property on the bean. This would give the expected result.

Steps to Reproduce

  1. Create a record with the API where you set an optional date field to the current date.
  2. Update this record by setting the date field tot NULL with the API PATCH method.
  3. The date field is not set to NULL but instead retains its old value.
Originally created by @imens-frankd on GitHub (Sep 28, 2023). While updating data by means of API PATCH method you can't set the value of a field to NULL. If you set a field to NULL in the json body of the PATCH method then this is ignored. #### Expected Behavior Explicitly setting a field to NULL in the PATCH method should result in setting the field to NULL in the database. #### Actual Behavior The field is not updated in the database. #### Possible Fix The API sets the NULL value correctly on the bean. The DBManager code however skips properties with NULL value. ''' # include/database/DBManager.php if (isset($bean->$field)) { $val = from_html($bean->$field); } else { continue; } ''' I assume this is by design to optimize the SQL queries. The APi should take this into account and translate the explicit NULL value in the PATCH to an empty string before setting the property on the bean. This would give the expected result. #### Steps to Reproduce 1. Create a record with the API where you set an optional date field to the current date. 2. Update this record by setting the date field tot NULL with the API PATCH method. 3. The date field is not set to NULL but instead retains its old value.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SuiteCRM-SuiteCRM#5103
No description provided.