Skip to content

Update Request Builder filters out updates to null #3204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
carlonnheim opened this issue Dec 12, 2022 · 6 comments
Closed

Update Request Builder filters out updates to null #3204

carlonnheim opened this issue Dec 12, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@carlonnheim
Copy link

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

@carlonnheim carlonnheim added the bug Something isn't working label Dec 12, 2022
@deekshas8
Copy link
Contributor

Hi @carlonnheim,

Thank you for raising this and also identifying the cause. I am able to reproduce the issue. I will create a backlog item for this and discuss within the team.

Will get back to you with an update once we have a fix.

@carlonnheim
Copy link
Author

Sounds great @deekshas8 , let me know if I can help with testing or similar. Thanks!

@Udineshsap13
Copy link

Udineshsap13 commented Jan 4, 2023

Hi @deekshas8,

Do you have an update on this issue on when it would be fixed.

@fwilhe
Copy link
Contributor

fwilhe commented Jan 4, 2023

Hi @Udineshsap13,

I'm working on it. The PR is open here. I can't give a date for when it will be released.

Best,
Florian

fwilhe added a commit that referenced this issue Jan 5, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
See #3204 for original issue
@fwilhe
Copy link
Contributor

fwilhe commented Jan 5, 2023

Hi @carlonnheim and @Udineshsap13

the fix has been merged to the main branch, but is not yet released. I'll keep you updated here.

Best,
Florian

@fwilhe
Copy link
Contributor

fwilhe commented Jan 6, 2023

Hi @carlonnheim and @Udineshsap13

we released version 2.13.0 with the fix included.

npmjs.com

github

Closing this issue,

Florian

@fwilhe fwilhe closed this as completed Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants