Skip to content

feat(firestore): add BSONBinary support - #18389

Open
ohmayr wants to merge 1 commit into
bson-pr1c-int32from
bson-pr1d-binary
Open

ohmayr wants to merge 1 commit into
bson-pr1c-int32from
bson-pr1d-binary

Conversation

@ohmayr

@ohmayr ohmayr commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

This PR adds support for BSONBinary in the Firestore Python SDK. BSONBinary` allows database applications to store subtyped binary data payloads (such as UUIDs, MD5 hashes, or custom binary subtypes) in Firestore documents.

  • BSONBinary Container Class: Implements BSONBinary(_BSONType) in google.cloud.firestore_v1.bson, wrapping binary payloads (bytes or bytearray) and a 1-byte BSON subtype tag ($0 \le \text{subtype} \le 255$, defaulting to 0).
  • Spec-Compliant Wire Serialization (_to_map_value):
    • subtype == 0 (generic binary): Serializes directly as raw bytes (bytes_value).
    • subtype != 0 (subtyped binary): Serializes as {"__binary__": bytes([subtype]) + data} (map_value).
  • Defensive Validation:
    • Raises TypeError for non-binary payloads or non-integer / boolean subtype tags.
    • Raises ValueError if subtype is outside the 1-byte range ($0 \le \text{subtype} \le 255$).
  • SDK Exports & Post-Processing: Exported BSONBinary in google.cloud.firestore and google.cloud.firestore_v1, and updated .librarian/generator-input/client-post-processing/firestore-integration.yaml.
  • Tests: Added 14 atomic unit tests in tests/unit/v1/test_bson.py and verified live sync and async write operations against Firestore Enterprise DB (enterprise-db-native-2).

Fixes b/562182261 🦕

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces the BSONBinary class to represent BSON binary data containers with subtypes for Firestore. It includes integration with the client post-processing configuration, exports the class in the package's public interfaces, and adds comprehensive unit and system tests to verify its behavior and serialization. I have no feedback to provide as there are no review comments.

@ohmayr
ohmayr added this pull request to stack #18386 September 16, 2026 01:10
@ohmayr
ohmayr marked this pull request as ready for review September 16, 2026 01:10
@ohmayr
ohmayr requested review from a team as code owners September 16, 2026 01:10
@ohmayr
ohmayr force-pushed the bson-pr1d-binary branch 2 times, most recently from 71cb746 to 9962001 Compare September 16, 2026 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant