GeezerVison is showing github.com — feat(firestore): add BSONRegex support by ohmayr · Pull Request #18394 · googleapis/google-cloud-python
Conversation
ohmayr
commented
Sep 16, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Adds the BSONRegex data type to support BSON regular expression field serialization in Google Cloud Firestore according to the official Firestore BSON specification.
BSONRegex Container Class: Introduces google.cloud.firestore_v1.bson.BSONRegex to encapsulate regex patterns (pattern: str) and option flags (options: str | re.RegexFlag | int).
- Flag Normalization: Automatically normalizes Python
re flag integers (re.IGNORECASE | re.MULTILINE) into sorted, unique BSON option flag strings (e.g., "im").
- Wire Serialization: Implements
_to_map_value() converting BSONRegex into the reserved {"__regex__": {"pattern": pattern, "options": options}} wire map representation.
- SDK Surface Export: Exported on top-level package namespaces (
google.cloud.firestore_v1 and google.cloud.firestore).
Fixes: b/562163604
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
gemini-code-assist[bot] reacted with eyes emoji
There was a problem hiding this comment.
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 BSONRegex class to represent BSON Regular Expression containers for Firestore, along with corresponding unit and system tests. The new class is integrated into the package's public API and supports pattern validation, option flag normalization (including conversion from Python re flags), serialization, and comparison operations. There are no review comments, and I have no feedback to provide.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main request is for test cases with invalid options
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but consider adding more system test cases (particularly with invalid options present)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…lidation
- Restrict BSONRegex options parameter to string only, removing re.RegexFlag and int support.
- Add client-side validation for BSON regex option characters ("i", "m", "s", "x", "u", "a"), raising ValueError on invalid options.
- Remove obsolete re-flag test and clean up unused import in test_bson.py.
Remove client-side regex options character validation and whitelist in
BSONRegex, letting the Firestore backend validate regex option flags.
Preserves alphabetical sorting and deduplication per BSON specification
while avoiding unhandled ValueError exceptions during read deserialization
when documents contain standard BSON options like 'l' (locale).
Fixes: b/562163604
Add sync and async system test cases verifying that writing a BSONRegex
with unsupported options (such as 'l') fails backend validation with
google.api_core.exceptions.InvalidArgument and an informative error
message on an Enterprise database.
Fixes: b/562163604
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
+1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|