diff options
author | Jordan Cook <jordan.cook@pioneer.com> | 2022-02-15 15:08:51 -0600 |
---|---|---|
committer | Jordan Cook <jordan.cook@pioneer.com> | 2022-02-15 15:08:52 -0600 |
commit | 35aecf2fdc056c69699850e4a6777f30ed4588e7 (patch) | |
tree | 1f37e0797a9bea83ebd90c88164337f4de90bf38 | |
parent | 9b0668807ccb6bfcfbc2de5144dfff03db9d45d1 (diff) | |
download | requests-cache-35aecf2fdc056c69699850e4a6777f30ed4588e7.tar.gz |
Fix handling BSON serializer differences between pymongo's bson and standalone bson codec.
-rw-r--r-- | HISTORY.md | 3 | ||||
-rw-r--r-- | pyproject.toml | 2 | ||||
-rw-r--r-- | requests_cache/serializers/preconf.py | 10 | ||||
-rw-r--r-- | tests/integration/test_filesystem.py | 2 |
4 files changed, 11 insertions, 6 deletions
@@ -1,5 +1,8 @@ # History +## 0.9.3 (Unreleased) +* Fix handling BSON serializer differences between pymongo's `bson` and standalone `bson` codec. + ## 0.9.2 (2022-02-15) * Fix serialization in filesystem backend with binary content that is also valid UTF-8 * Fix some regression bugs introduced in 0.9.0: diff --git a/pyproject.toml b/pyproject.toml index 71738d7..29e591d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "requests-cache" -version = "0.9.2" +version = "0.9.3" description = "A transparent persistent cache for the requests library" authors = ["Roman Haritonov"] maintainers = ["Jordan Cook"] diff --git a/requests_cache/serializers/preconf.py b/requests_cache/serializers/preconf.py index 35453b5..ed19fb4 100644 --- a/requests_cache/serializers/preconf.py +++ b/requests_cache/serializers/preconf.py @@ -69,13 +69,15 @@ except ImportError as e: # BSON serializer try: try: - from bson import json_util as bson + from bson import decode as _bson_loads + from bson import encode as _bson_dumps except ImportError: - import bson + from bson import dumps as _bson_dumps + from bson import loads as _bson_loads bson_serializer = SerializerPipeline( - [bson_preconf_stage, bson], is_binary=False - ) #: Complete BSON serializer; uses pymongo's ``bson.json_util`` if installed, otherwise standalone ``bson`` codec + [bson_preconf_stage, Stage(dumps=_bson_dumps, loads=_bson_loads)], is_binary=True + ) #: Complete BSON serializer; uses pymongo's ``bson`` if installed, otherwise standalone ``bson`` codec except ImportError as e: bson_serializer = get_placeholder_class(e) diff --git a/tests/integration/test_filesystem.py b/tests/integration/test_filesystem.py index 4a4884e..b651186 100644 --- a/tests/integration/test_filesystem.py +++ b/tests/integration/test_filesystem.py @@ -60,7 +60,7 @@ class TestFileCache(BaseCacheTest): session = self.init_session(serializer=serializer_name) num_files = 20 for i in range(num_files): - session.cache.responses[f'key_{i}'] = f'value_{i}' + session.cache.responses[f'key_{i}'] = {f'value_{i}': i} expected_extension = serializer_name.replace('pickle', 'pkl') assert len(list(session.cache.paths())) == num_files |