Skip to content

Fix: authtoken.TokenProxy cannot be proxy when not installed #7442 #7571

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

Conversation

KPilnacek
Copy link
Contributor

Used the first of solutions @kalekseev proposed in #7442 (comment)

@terencehonles
Copy link
Contributor

I arrived independently at the other solution @kalekseev proposed. Either is probably fine to use from my point of view since I don't use the model and may not ever, but I think my solution of throwing ImproperlyConfigured when the TokenProxy class is instantiated might be a slightly better user experience.

importlib.reload(rest_framework.authtoken.models)
# Set the proxy and abstract properties back to the version,
# where authtoken is among INSTALLED_APPS.
importlib.reload(rest_framework.authtoken.models)
Copy link
Contributor

@terencehonles terencehonles Oct 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the solution that's picked, you may want to edit this to check that the two models do exist and that they are indeed abstract instead of just checking that the import works. That way if Django's implementation changes we'd be able to notice the difference and either remove the test or special case it depending on the supported version.

Either way, nice to have a test! I started searching for issues before writing a test and this will help me too 🙂

Comment on lines +29 to +31
# Set the proxy and abstract properties back to the version,
# where authtoken is among INSTALLED_APPS.
importlib.reload(rest_framework.authtoken.models)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you probably want to put the final reload in a finally: block, that way the imports aren't messed up for a subsequent test. I ran into this issue while adding tests to my PR.

@tomchristie
Copy link
Member

This seems to be sufficient to me, let's go with this.

@tomchristie tomchristie merged commit 79daf31 into encode:master Oct 9, 2020
@DeeeeLAN
Copy link

When do you expect a new release that will include this fix?

@tomchristie tomchristie mentioned this pull request Oct 13, 2020
@sdebnath
Copy link

Can we get a git tag added for this version and a release updated on pypi?

https://pypi.org/project/djangorestframework/

Still shows 3.12.1 as being the latest.

@naggie
Copy link

naggie commented Oct 21, 2020

I'm also eagerly awaiting the PyPi publish. Thanks for the fix!

@banagale
Copy link

banagale commented Oct 25, 2020

@naggie @sdebnath Here's a line for your requirements.txt to patch in the new release direct from github:

Django==3.1.2
# ...
# Temporary DRF requirement for #7571
git+https://github.com/encode/[email protected]
# ...

@sdebnath
Copy link

Thanks @banagale - looking forward to the distribution update down the road.

sigvef pushed a commit to sigvef/django-rest-framework that referenced this pull request Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants