Skip to content
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

TypeError when registering ForwardRefs in python 3.10.2 & 3.9.10 #504

Closed
codekuu opened this issue Jan 19, 2022 · 4 comments
Closed

TypeError when registering ForwardRefs in python 3.10.2 & 3.9.10 #504

codekuu opened this issue Jan 19, 2022 · 4 comments

Comments

@codekuu
Copy link

codekuu commented Jan 19, 2022

The problem

TypeError: Invalid first argument to `register()`. ForwardRef('CachedResponse') is not a class.

Since requests-cache is using cattr as serializers (https://github.com/reclosedev/requests-cache/blob/master/requests_cache/serializers/cattrs.py) this issue is related.

Looks like there is already an issue open for cattr regarding this error but a workaround would be nice until python is patched (if they even patch?).
issue: python-attrs/cattrs#206

Expected behavior

-||-

Steps to reproduce the behavior

Start any application utilizing requests-cache

Workarounds

python-attrs/cattrs#206

Environment

  • requests-cache version: all versions utilizing cattr
  • Python version: 3.10.2 & 3.9.10
  • Platform: all related to python version above
@codekuu codekuu added the bug label Jan 19, 2022
@hitman-gdg
Copy link

Python 3.9.10 Changelog:
bpo-46032: The registry() method of functools.singledispatch() functions checks now the first argument or the first parameter annotation and raises a TypeError if it is not supported. Previously unsupported “types” were ignored (e.g. typing.List[int]) or caused an error at calling time (e.g. list[int]).

@pmatias
Copy link

pmatias commented Jan 19, 2022

I can confirm this bug. There's no way to specify an older 3.9/3.10 version on GitHub Actions (e.g. 3.9.9) so we're kinda stuck on this one until it's fixed here :/

@JWCook
Copy link
Member

JWCook commented Jan 19, 2022

Good news: this has already been fixed in requests-cache 0.9.1 (see #501). I opened that cattrs issue while looking into this issue, and details on the fix/workaround are posted there.

@JWCook JWCook closed this as completed Jan 19, 2022
@pmatias
Copy link

pmatias commented Jan 20, 2022

That definitely helped. Thanks for the assistance!

mbaluch pushed a commit to RedHatProductSecurity/osidb that referenced this issue Jan 31, 2022
Due to some changes very high up the stack in CPython 3.9.10 [1],
requests-cache does no longer work properly [2] and will fail due to
its dependency on cattrs [3] which uses functools.singledispatch
which is what changed in the aforementioned CPython update.

The requests-cache devs have implemented a workaround in version
0.9.1 which is the only thing that they can do since cattrs does
not explicitly support their usage (and are not willing to
implement a workaround at their level).

This commit upgrades to said version.

[1] https://bugs.python.org/issue46032
[2] requests-cache/requests-cache#504
[3] python-attrs/cattrs#206
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants