Cosmos: Fix replaceItem bypassing customItemSerializer#48529
Cosmos: Fix replaceItem bypassing customItemSerializer#48529lloydmeta wants to merge 3 commits intoAzure:mainfrom
Conversation
|
Thank you for your contribution @lloydmeta! We will review the pull request and get back to you soon. |
d108d78 to
bd4ea98
Compare
FabianMeiswinkel
left a comment
There was a problem hiding this comment.
Looks goo to me - Thanks!
kushagraThapar
left a comment
There was a problem hiding this comment.
Thanks @lloydmeta for fixing this bug on the SDK, appreciate your contributions.
Add a regression test Signed-off-by: lloydmeta <lloydmeta@gmail.com>
0281bb7 to
1550599
Compare
|
@lloydmeta the newly added tests are failing on this pipeline, can you please check and fix them? https://dev.azure.com/azure-sdk/public/_build/results?buildId=6048391&view=ms.vss-test-web.build-test-results-tab&runId=60434280&paneView=debug |
There was a problem hiding this comment.
Pull request overview
Fixes CosmosAsyncContainer.replaceItem to respect the effective (custom) item serializer by removing the eager POJO→Document conversion that bypassed user-provided customItemSerializer.
Changes:
- Updated
replaceItemflow to pass the raw item object through the replace pipeline soDocument.fromObject(..., effectiveItemSerializer)can invoke the correct serializer. - Added an emulator test to validate
replaceItemrespects customObjectMappersettings (e.g.,JsonInclude.NON_NULL). - Added a CHANGELOG entry describing the bug fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncContainer.java | Stops pre-serializing items via SDK-internal mapper so replace operations use the effective/custom serializer. |
| sdk/cosmos/azure-cosmos/CHANGELOG.md | Documents the serializer-bypass bug fix under “Bugs Fixed”. |
| sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosItemSerializerTest.java | Adds coverage ensuring replaceItem honors request-level custom serializer/ObjectMapper behavior. |
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncContainer.java
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncContainer.java
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosItemSerializerTest.java
Show resolved
Hide resolved
Signed-off-by: lloydmeta <lloydmeta@gmail.com>
Signed-off-by: lloydmeta <lloydmeta@gmail.com>
I gave it a go and pushed a commit that has a real fix, f48f962 , but currently there is a failure in a test for something that is not related at all.
is failing with There is a test that actually looks quite prone to flakiness it compares parallel vs serial execution and expects the former to be faster than the latter with no tolerance.... not sure what machines you're executing on and the exact set up you hav to ensure parallel is always faster but it feels like it's worthwhile to consider less ambitious like // allow some leniency variations
assertThat(durationParallel).isCloseTo(durationSerial, Percentage.withPercentage(5)) ;
// Or do one or the other...
assertThat(durationParallel).satisfiesAnyOf(
it -> assertThat(it).isLessThan(durationSerial),
it -> assertThat(it).isCloseTo(durationSerial, Percentage.withPercentage(5))
); |
Description
CosmosAsyncContainer.replaceItemeagerly converted the POJO to aDocumentviaInternalObjectNode.fromObject(item), which serialises through the SDK's internalObjectMapperrather than the user'scustomItemSerializer. The resultingDocumentthen short-circuits
Document.fromObject(already aDocument, returned as-is),so the custom serialiser is never invoked.
This means any
ObjectMapperconfiguration on the custom serialiser (e.g.WRITE_DATES_AS_TIMESTAMPS = false,JsonInclude.NON_NULL, custom modules) issilently ignored for
replaceItem, whilecreateItemandupsertItemwork correctly.The fix removes the intermediate
InternalObjectNode.fromObjectconversion and passesthe raw POJO through the replace chain, matching how
createItemandupsertItemalready work.
Fixes #48527
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines