Repository navigation
Python: Return plain ints for bson Int64 values from Azure DocumentDB - #10322
Open
ni (nniiovoo) wants to merge 2 commits into
Open
ni (nniiovoo) wants to merge 2 commits into
ni (nniiovoo) wants to merge 2 commits into
Conversation
Signed-off-by: NNIIOVO <haimingni44@gmail.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The regression omits nested Int64 values, allowing a shallow normalizer to pass while nested data may still fail to round-trip through get() and upsert().
1 open issue
What changed in this PR
This PR fixes BSON Int64 handling in the Python Azure DocumentDB integration, addressing #10321 so large integer keys can be read and returned records can be upserted again.
Changes:
- Recursively converts returned
Int64values to plain Python integers before key validation. - Adds a regression test covering large integer keys, integer fields, list values, and re-upserting.
- Preserves strict write-side input validation.
| File | Description |
|---|---|
python/packages/azure-documentdb/tests/azure_documentdb/test_vector_store.py |
Adds integer normalization and round-trip regression coverage. |
python/packages/azure-documentdb/agent_framework_azure_documentdb/_vector_store.py |
Normalizes BSON integers recursively during record deserialization. |
Review effort: Balanced
Comment on lines
+142
to
+151
| "tags": [Int64(big)], | ||
| "contentVector": [1.0, 0.0, 0.0], | ||
| } | ||
| ]) | ||
|
|
||
| records = await collection.get([big], include_vectors=True) | ||
|
|
||
| assert type(records[0]["id"]) is int and records[0]["id"] == big | ||
| assert type(records[0]["number"]) is int | ||
| assert type(records[0]["tags"][0]) is int |
2 tasks done
Signed-off-by: NNIIOVO <haimingni44@gmail.com>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Motivation & Context
PyMongo decodes BSON int64 values as
bson.int64.Int64.AzureDocumentDBCollectionpassed those straight on, soget()raisedTypeError(and searchIntegrationInvalidResponseException) for any int key outside the 32-bit range (the key check usestype(value) is not int), and int data fields came back asInt64, which core's msgspec encoder rejects when the record is upserted again. Repro is in #10321.Description & Review Guide
_deserialize_store_models_to_dictsnow turnsInt64values back into plainint(recursively, so list and dict fields are covered too) before the key check.get()/search work for any keyupsert()accepted, and the records can be written again. The write-side checks are unchanged._prepare_key, so the strict type checks on user input stay as they are.Tests: I added a test that returns
Int64values for the key, an int field and a list field, then upserts the record again (it fails on main).Related Issue
Fixes #10321
AI Assistance
AI assistance details: issue analysis, implementation, tests, and this description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.