- Notifications
You must be signed in to change notification settings - Fork 65
Description
Describe the bug
I have an oData v2 service exposing an entity with fields of String type. If I try to update one of those fields to become the value null
they are discarded silently.
To Reproduce
You need a service exposing an entity with a nullable property. Then do this
// Get the instance to edit let instance = await myEntityApi.requestBuilder().getByKey('somekey').execute(someDestination); // Set the property to null instance.myNullableStringProperty = null; // Send the update request await myEntityApi.requestBuilder().update(instance).execute(someDestination);
This results in no changed fields being identified and the update is silently discarded.
Expected behavior
A PATCH
with the payload {"myNullableStringProperty":null}
should be sent
Screenshots
N/A
Used Versions:
- node version via
node -v
: v16.16.0 - npm version via
npm -v
: 8.19.2 - SAP Cloud SDK version you used as dependency: ^2.10.0
Code Examples
I believe the root cause is in packages/odata-v2/src/request-builder/update-request-builder.ts
. When looking for navigation properties and complex types it is checking the typeof
being object, which filters out also scalar fields being set to null
.
function removeNavPropsAndComplexTypes( body: Record<string, any> ): Record<string, any> { return removePropertyOnCondition(([, val]) => typeof val === 'object', body); // *** this causes the removal since typeof null -> 'object' }
Log file
N/A
Impact / Priority
We rely heavily on the cloud sdk for our integrations. The issue causes silent errors, i.e. the caller gets a successful response despite backend update not actually coming through. If we put these requests into batches they will be sent with an empty ({}
) payload, which our backend services consider an error.
Affected development phase: Release
Impact: Impaired
Timeline: Go-Live is in 3 months.
Additional context
Backend oData service is from SAP Business ByDesign