fix: CustomItemSerializer not applied correctly in queries and SqlParameter [Cosmos]#48702
fix: CustomItemSerializer not applied correctly in queries and SqlParameter [Cosmos]#48702xinlian12 wants to merge 0 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes Cosmos DB query behavior when a CustomItemSerializer is configured by preventing it from deserializing internal SDK query structures, and by ensuring query parameters can be serialized with the effective item serializer.
Changes:
- Force internal query pipeline request options to use
CosmosItemSerializer.DEFAULT_SERIALIZER(instead ofnull) to avoid leaking client-level custom serializers into internal deserialization. - Add internal plumbing to re-serialize
SqlParametervalues using the effective serializer at query execution time. - Introduce internal bridge method to apply parameter re-serialization across packages.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/SqlQuerySpec.java | Adds internal method to apply an effective serializer to all parameters. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/SqlParameter.java | Stores raw parameter values and adds internal re-serialization hook. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ModelBridgeInternal.java | Exposes internal bridge method to apply serializer to query parameters. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/PipelinedQueryExecutionContextBase.java | Applies effective serializer to parameters at query execution time. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/PipelinedDocumentQueryExecutionContext.java | Forces DEFAULT serializer on internal pipeline request options to prevent custom serializer leaks. |
| .coding-harness/spec.json | Adds harness metadata/spec for the reported issue and intended fix. |
|
@sdkReviewAgent-2 |
|
✅ Review complete (54:56) No new comments — existing review coverage is sufficient. Steps: cross-sdk, history, past-prs, quality, sanity-check, synthesis, test-coverage |
|
/azp run java - cosmos - spark |
|
/azp run java - cosmos - kafka |
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
2 similar comments
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run java - cosmos - spark |
|
/azp run java - cosmos - kafka |
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
2 similar comments
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run java - cosmos - kafka |
|
/azp run java - cosmos - spark |
|
/azp run java - cosmos - tests |
8838549 to
f6140fa
Compare
|
@sdkReviewAgent-2 |
|
/azp run java - cosmos - kafka |
|
/azp run java - cosmos - spark |
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
2 similar comments
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
✅ Review complete (45:12) Posted 2 inline comment(s). Steps: ✓ context, correctness, cross-sdk, design, history, past-prs, synthesis, test-coverage |
|
@sdkReviewAgent-2 |
|
✅ Review complete (45:25) Posted 1 inline comment(s). Steps: ✓ context, correctness, cross-sdk, design, history, past-prs, synthesis, test-coverage |
|
/azp run java - cosmos - spark |
|
/azp run java - cosmos - kafka |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
The failed tests are all related to thin client due to recent disablement |
|
/check-enforcer override |
1 similar comment
|
/check-enforcer override |
f0d09d4 to
8a671dd
Compare
Summary
Fixes #45521
Two bugs with
CustomItemSerializer:Bug 1 Deserialization failures in ORDER BY/GROUP BY/aggregate/DISTINCT queries
When
customItemSerializeris configured onCosmosClientBuilder, complex queries (ORDER BY, GROUP BY, VALUE, COUNT, SUM, DISTINCT, HybridSearch) fail because the custom serializer leaks into the internal query pipeline and is used to deserialize internal SDK structures (OrderByRowResult,Document, etc.).Root cause:
PipelinedDocumentQueryExecutionContext.createBaseComponentFunction()calledsetCustomItemSerializer(null)on cloned request options, butRxDocumentClientImpl.getEffectiveItemSerializer()falls back to the client-leveldefaultCustomSerializerwhen the request-level serializer isnull.Fix: Set
CosmosItemSerializer.DEFAULT_SERIALIZERinstead ofnullon internal request options. This causesgetEffectiveItemSerializer()to returnDEFAULT_SERIALIZERimmediately without falling through to the client-level custom serializer.Bug 2 SqlParameter ignores customItemSerializer
SqlParameter.setValue()delegates toJsonSerializable.set()which hardcodesINTERNAL_DEFAULT_SERIALIZER. Custom serialization settings (e.g., dates as ISO strings) are never applied to query parameters.Fix: Added
rawValuefield toSqlParameterto retain the original value, plusapplySerializer()to re-serialize with a custom serializer. Called fromPipelinedQueryExecutionContextBase.createAsync()where the effective serializer is known.Changes
PipelinedDocumentQueryExecutionContext.javanullDEFAULT_SERIALIZERin 4 internal pipeline pathsPipelinedQueryExecutionContextBase.javaSqlParameter.javarawValuefield +applySerializer()methodSqlQuerySpec.javaapplySerializerToParameters()Testing
Build compiles cleanly. Existing tests unaffected. Additional test cases for ORDER BY/GROUP BY/aggregate queries with custom serializer and SqlParameter serialization should be added.