Skip to content

Update Request Builder filters out updates to null #3204

@carlonnheim

Description

@carlonnheim

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions