-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👽 Wrap the json serialization/deserialization to force the UUID repre…
…sentation to LEGACY - Created a simple class (`json_wrappers.py`) which encapsulates the correct settings that we need for serializing and deserializing the JSON representations with the correct UUID representation - Changed all the references in the `emission` directory to use the new wrapper functions - Including cleaning up prior hardcoded attempts at cleanup, such as 3b456e7#diff-cfddece09bbf132974a13acdfb77be4e585a4bff39999f559dc8200c1ffbe78d Additional Context: - e-mission/e-mission-docs#856 (comment) - https://pymongo.readthedocs.io/en/stable/examples/uuid.html - 9c683cf - 6ac02a2 - edd8b77 As of 4.3.3, the LEGACY_JSON_OPTIONS also has an UNSPECIFIED UUID representation > bson.json_util.LEGACY_JSON_OPTIONS: bson.json_util.JSONOptions = > JSONOptions(strict_number_long=False, datetime_representation=0, > strict_uuid=False, json_mode=0, document_class=dict, tz_aware=False, > uuid_representation=UuidRepresentation.UNSPECIFIED, > unicode_decode_error_handler='strict', tzinfo=None, > type_registry=TypeRegistry(type_codecs=[], fallback_encoder=None), > datetime_conversion=DatetimeConversion.DATETIME)¶ Testing done: - Ensured that there were no imports of json_utils ``` $ find emission -name \*.py | xargs grep json_utils $ ``` - Ensured that all `bju` prefixes were replaced, other than in the wrapper itself ``` $ find emission -name \*.py | xargs grep bju emission/storage/json_wrappers.py:import bson.json_util as bju emission/storage/json_wrappers.py:wrapped_object_hook = lambda s: bju.object_hook(s, emission/storage/json_wrappers.py: json_options = bju.RELAXED_JSON_OPTIONS.with_options( emission/storage/json_wrappers.py:wrapped_default = lambda o: bju.default(o, json_options = bju.LEGACY_JSON_OPTIONS) emission/storage/json_wrappers.py:wrapped_dumps = lambda o: bju.dumps(o, json_options = bju.LEGACY_JSON_OPTIONS.with_options( emission/storage/json_wrappers.py:wrapped_loads = lambda s: bju.loads(s) ``` - Ensured that all `esj` imports used the `wrapped` version of the name ``` $ find emission -name \*.py | xargs grep esj | egrep -v "import|esj.wrapped" | wc -l 0 ```
- Loading branch information
Showing
24 changed files
with
153 additions
and
141 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import bson.json_util as bju | ||
import bson.binary as bbin | ||
|
||
# Create wrappers to load and save with the legacy UUID representation | ||
# these wrappers are designed to be drop-in replacements for the existing `bson.json_util.default` | ||
# and `bson.json_util.object_hook` | ||
|
||
wrapped_object_hook = lambda s: bju.object_hook(s, | ||
json_options = bju.RELAXED_JSON_OPTIONS.with_options( | ||
uuid_representation=bbin.UuidRepresentation.PYTHON_LEGACY)) | ||
|
||
wrapped_default = lambda o: bju.default(o, json_options = bju.LEGACY_JSON_OPTIONS) | ||
|
||
# TODO: Why are the wrapped_default and wrapped_dumps different | ||
# need to see whether the UUID representation really does need to be specified | ||
# and unify them | ||
wrapped_dumps = lambda o: bju.dumps(o, json_options = bju.LEGACY_JSON_OPTIONS.with_options( | ||
uuid_representation= bbin.UuidRepresentation.PYTHON_LEGACY)) | ||
|
||
# This doesn't currently seem to require any wrapping, but let's abstract it | ||
# out anyway to avoid hacky changes by interns later | ||
wrapped_loads = lambda s: bju.loads(s) |
This file contains 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 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 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.