summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Cook <JWCook@users.noreply.github.com>2022-01-15 11:12:42 -0600
committerGitHub <noreply@github.com>2022-01-15 11:12:42 -0600
commitddf7ad897fe95b179c201e9a912511040eaea2cc (patch)
tree7e62e232694ae8915f0c95b77b8281371b1c1656
parent0b8f7c8ba3cdee8408846d9570a3e7ac3a0eb98d (diff)
parent4c8e386b3a887cdd35c046d426b1247c9018aa0c (diff)
downloadrequests-cache-ddf7ad897fe95b179c201e9a912511040eaea2cc.tar.gz
Merge pull request #503 from JWCook/py3.10.2-compat
Switch to a different method of resolving ForwardRefs during deserialization for python 3.10.2 compatibility
-rw-r--r--HISTORY.md3
-rw-r--r--requests_cache/serializers/cattrs.py8
2 files changed, 6 insertions, 5 deletions
diff --git a/HISTORY.md b/HISTORY.md
index 8425e0c..f13459b 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -1,7 +1,8 @@
# History
## 0.9.1 (Unreleased)
-* Add support for key-only request parameters
+* Add support for python 3.10.2 (regarding resolving `ForwardRef` types during deserialization)
+* Add support for key-only request parameters (regarding hashing request data for cache key creation)
* Reduce verbosity of log messages when encountering an invalid JSON request body
## 0.9.0 (2022-01-01)
diff --git a/requests_cache/serializers/cattrs.py b/requests_cache/serializers/cattrs.py
index 7b483d7..7652cad 100644
--- a/requests_cache/serializers/cattrs.py
+++ b/requests_cache/serializers/cattrs.py
@@ -65,10 +65,10 @@ def init_converter(factory: Callable[..., GenConverter] = None):
converter.register_unstructure_hook(HTTPHeaderDict, dict)
converter.register_structure_hook(HTTPHeaderDict, lambda obj, cls: HTTPHeaderDict(obj))
- # Tell cattrs that a 'CachedResponse' forward ref is equivalent to the CachedResponse class
- converter.register_structure_hook(
- ForwardRef('CachedResponse'),
- lambda obj, cls: converter.structure(obj, CachedResponse),
+ # Tell cattrs to resolve forward references (required for CachedResponse.history)
+ converter.register_structure_hook_func(
+ lambda cls: cls.__class__ is ForwardRef,
+ lambda obj, cls: converter.structure(obj, cls.__forward_value__),
)
return converter