Skip to content

Python: Return plain ints for bson Int64 values from Azure DocumentDB - #10322

Open
ni (nniiovoo) wants to merge 2 commits into
microsoft:mainfrom
nniiovoo:python-documentdb-int64-read
Open

ni (nniiovoo) wants to merge 2 commits into
microsoft:mainfrom
nniiovoo:python-documentdb-int64-read

Conversation

@nniiovoo

Copy link
Copy Markdown
Contributor

Motivation & Context

PyMongo decodes BSON int64 values as bson.int64.Int64. AzureDocumentDBCollection passed those straight on, so get() raised TypeError (and search IntegrationInvalidResponseException) for any int key outside the 32-bit range (the key check uses type(value) is not int), and int data fields came back as Int64, which core's msgspec encoder rejects when the record is upserted again. Repro is in #10321.

Description & Review Guide

  • What are the major changes? _deserialize_store_models_to_dicts now turns Int64 values back into plain int (recursively, so list and dict fields are covered too) before the key check.
  • What is the impact of these changes? Records read back from DocumentDB have plain ints, so get()/search work for any key upsert() accepted, and the records can be written again. The write-side checks are unchanged.
  • What do you want reviewers to focus on? I normalized on read instead of relaxing _prepare_key, so the strict type checks on user input stay as they are.

Tests: I added a test that returns Int64 values 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

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: issue analysis, implementation, tests, and this description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Signed-off-by: NNIIOVO <haimingni44@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 Int64 values 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
Signed-off-by: NNIIOVO <haimingni44@gmail.com>
@nniiovoo
ni (nniiovoo) deployed to github-app-auth November 12, 2026 21:50 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
github-app-auth — 52abe298 Deployed Nov 12, 2026 by nniiovoo via add_label #27759
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Azure DocumentDB: get() fails for int keys outside the 32-bit range (PyMongo returns them as Int64)

2 participants