-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-2680 Breaking changes to DBRef BSON+JSON decoding #722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2170401
PYTHON-2680 Ensure $regularExpression options are a string when parsi…
ShaneHarvey 7a67270
PYTHON-2680 Make breaking changes to DBRef BSON+JSON encoding/decodin…
ShaneHarvey 54944c0
PYTHON-2680 Add buggy BSON DBRef refactor
ShaneHarvey 75d485e
PYTHON-2680 Fix C DBRef hook, return new dbref object without decref
ShaneHarvey f822569
PYTHON-2680 Fix test_bad_dbref due to $ref/$id changes
ShaneHarvey ec2ab33
PYTHON-2680 Add DBRef spec prose tests
ShaneHarvey bbfd4c0
PYTHON-2680 Resync bson corpus tests
ShaneHarvey aa4f6a3
PYTHON-2680 Update docs and cleanup
ShaneHarvey 42e7180
PYTHON-2680 Revert PYTHON-2883 changes
ShaneHarvey b1660d5
Merge branch 'master' into PYTHON-2680
ShaneHarvey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,9 +121,6 @@ | |
"x": re.X, | ||
} | ||
|
||
# Dollar-prefixed keys which may appear in DBRefs. | ||
_DBREF_KEYS = frozenset(['$id', '$ref', '$db']) | ||
|
||
|
||
class DatetimeRepresentation: | ||
LEGACY = 0 | ||
|
@@ -463,7 +460,9 @@ def object_pairs_hook(pairs, json_options=DEFAULT_JSON_OPTIONS): | |
def object_hook(dct, json_options=DEFAULT_JSON_OPTIONS): | ||
if "$oid" in dct: | ||
return _parse_canonical_oid(dct) | ||
if "$ref" in dct: | ||
if (isinstance(dct.get('$ref'), str) and | ||
"$id" in dct and | ||
isinstance(dct.get('$db'), (str, type(None)))): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the breaking DBRef JSON decoding change. |
||
return _parse_canonical_dbref(dct) | ||
if "$date" in dct: | ||
return _parse_canonical_datetime(dct, json_options) | ||
|
@@ -675,10 +674,6 @@ def _parse_canonical_regex(doc): | |
|
||
def _parse_canonical_dbref(doc): | ||
"""Decode a JSON DBRef to bson.dbref.DBRef.""" | ||
for key in doc: | ||
if key.startswith('$') and key not in _DBREF_KEYS: | ||
# Other keys start with $, so dct cannot be parsed as a DBRef. | ||
return doc | ||
return DBRef(doc.pop('$ref'), doc.pop('$id'), | ||
database=doc.pop('$db', None), **doc) | ||
|
||
|
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
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
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
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
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
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
Oops, something went wrong.
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.
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.
This is the breaking DBRef BSON decoding change.