customer opt-in for ascii expansion - #48914
Conversation
|
@sdkReviewAgent-2 |
|
/azp run python - cosmos - tests |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 8 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Note
This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.
|
@sdkReviewAgent-2 |
This comment has been minimized.
This comment has been minimized.
|
@sdkReviewAgent-2 |
|
/azp run python - cosmos - tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run python - cosmos - tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Note
This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.
|
/azp run python - cosmos - tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
@sdkReviewAgent-2 |
There was a problem hiding this comment.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Note
This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.
|
/azp run python - cosmos - tests |
|
/azp run python - cosmos - tests |
|
@sdkReviewAgent-2 |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
One or more custom setup steps configured for this repository failed during this Copilot code review run: Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review. Note You can configure setup steps for Copilot code review separately from Copilot cloud agent with a |
There was a problem hiding this comment.
🟢 Approval recommended
The option is correctly scoped and validated, with comprehensive sync, async, transport, resilience, and live coverage.
Review details
- Files reviewed: 28/28 changed files
- Comments generated: 0 new
- Review effort level: Balanced
This comment has been minimized.
This comment has been minimized.
|
✅ Review complete (17:22) Posted 2 inline comment(s). Steps: ✓ context, correctness, cross-sdk, design, history, past-prs, synthesis, test-coverage |
[Pilot] PR Pipeline Failure AnalysisWhat failedTwo separate, unrelated failures were detected on PR #48914 (head
Relevant pipeline outputRecommended next steps
|
|
@sdkReviewAgent-2 |
|
/azp run python - cosmos - tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
🟡 Changes recommended
The new PATCH header uses the RFC media type instead of Cosmos DB’s documented application/json_patch+json value.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (3)
Previously missed (2) — in code that hasn't changed since the last review.
sdk/cosmos/azure-cosmos/tests/test_transport_body_encoding.py:289
- This assertion codifies the RFC media type rather than Cosmos DB's required PATCH value,
application/json_patch+json. Update it so the transport test catches regressions to an unsupported content type.
This issue also appears on line 366 of the same file.
sdk/cosmos/azure-cosmos/CHANGELOG.md:16
- The release note names the wrong PATCH media type. Cosmos DB documents
application/json_patch+json(underscore), so this should match the corrected runtime header rather than describe the RFC 6902 hyphenated type.
sdk/cosmos/azure-cosmos/tests/test_transport_body_encoding.py:366
- The async assertion should also expect Cosmos DB's required
application/json_patch+jsonvalue; the hyphenated RFC media type is not the service's documented PATCH content type.
"application/json-patch+json",
- Files reviewed: 28/28 changed files
- Comments generated: 1
- Review effort level: Balanced
|
@sdkReviewAgent-2 |
|
/azp run python - cosmos - tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
🔵 Needs a closer look
Wire serialization and HTTP behavior change across both transports and retry paths, warranting final human validation.
Review details
- Files reviewed: 28/28 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Problem-
The Python SDK currently serializes JSON request bodies with ASCII escaping enabled. As a result, non-ASCII characters are expanded before being sent to Cosmos DB.
For example:
日 → \u65e5
A character that requires 3 bytes in UTF-8 becomes 6 bytes after escaping. The service measures the 2 MiB limit against the UTF-8 length of the JSON representation it receives, so documents containing large amounts of CJK or other non-ASCII text can exceed that limit even when their compact UTF-8 representation is well below it.
This blocked customers from ingesting otherwise valid documents.
Solution-
This change adds the following opt-in client option:
CosmosClient(
endpoint,
credential,
enable_compact_utf8_item_writes=True,
)
When enabled, item bodies for create, upsert, replace, patch, and transactional batch operations are serialized using compact UTF-8 instead of ASCII escape sequences.
The default remains False , so existing applications retain their current serialization behavior.
The implementation also:
Content-Lengthbehavior, reusing the byte length produced while validating the compact body rather than encoding the full body a second time.Customer impact-
Customers can opt in to send large Unicode-heavy documents without unnecessary \uXXXX expansion. A document whose escaped JSON exceeds the 2 MiB request size limit may remain below it when sent as compact UTF-8.
The stored item and the values returned on reads are identical either way, since both encodings describe the same JSON document; only the bytes on the wire differ.
Validation-
Added sync and async coverage for: