Django-rest-framework: TokenProxy can't be proxy model when Token is abstract model

Created on 30 Jul 2020  Â·  7Comments  Â·  Source: encode/django-rest-framework

This is a followup of https://github.com/encode/django-rest-framework/pull/7341#issuecomment-666108668 discussion

Token become abstract if rest_framework.authtoken not in settings.INSTALLED_APPS . For example django-rest-auth imports rest_framework.authtoken.models.Token as default value but if project provides its own token model then rest_framework.authtoken not required in INSTALLED_APPS. Same thing will happen if someone needs a CustomToken that extends Token in that case he wants Token model to be abstract.

Checklist

  • [x] I have verified that that issue exists against the master branch of Django REST framework.
  • [x] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • [x] This is not a usage question. (Those should be directed to the discussion group instead.)
  • [x] This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • [x] I have reduced the issue to the simplest possible case.
  • [ ] I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

Import rest_framework.authtoken.models while 'rest_framework.authtoken' not in settings.INSTALLED_APPS.

Bug

Most helpful comment

I'm also facing this issue, after upgrading from 3.11.0. The error is Abstract base class containing model fields not permitted for proxy model 'TokenProxy'., which is triggered by https://github.com/st4lk/django-rest-social-auth/blob/996a1c5f431defac8d5def96683ad1413499ec2e/rest_social_auth/serializers.py#L6

Adding rest_framework.authtoken in INSTALLED_APPS does not help. Is there anything that other packages, like rest_social_auth, need to change to make it work?

My specific error message is on #7561, which is marked as duplicate to this issue.

All 7 comments

Thanks @kalekseev!

First guess, making TokenProxy proxy depend on whether 'rest_framework.authtoken' is installed (to mirror the Token abstract behaviour) should™ solve this... 😬

    proxy = 'rest_framework.authtoken' in settings.INSTALLED_APPS

First guess, making TokenProxy proxy depend on whether 'rest_framework.authtoken' is installed (to mirror the Token abstract behaviour) should™ solve this... 😬

    proxy = 'rest_framework.authtoken' in settings.INSTALLED_APPS

TokenProxy should be abstract too

proxy = 'rest_framework.authtoken' in settings.INSTALLED_APPS
abstract  = 'rest_framework.authtoken' not in settings.INSTALLED_APPS

A radical solution could be:

if 'rest_framework.authtoken' in settings.INSTALLED_APPS:
    class TokenProxy:
        ...

I m facing same issue while deploying the qeb app to ec2 instance, can someone tell wat is the solution? I have used djoser module for authentication

I basically arrived at the if/else solution suggested above and I submitted it for review. I think right now either #7571 or #7584 will fix the issue if anyone needs a quick fix and doesn't want to add authtoken into their installed apps.

Still facing this error while using djoser.
Had to add rest_framework.authtoken in INSTALLED_APPS

I'm also facing this issue, after upgrading from 3.11.0. The error is Abstract base class containing model fields not permitted for proxy model 'TokenProxy'., which is triggered by https://github.com/st4lk/django-rest-social-auth/blob/996a1c5f431defac8d5def96683ad1413499ec2e/rest_social_auth/serializers.py#L6

Adding rest_framework.authtoken in INSTALLED_APPS does not help. Is there anything that other packages, like rest_social_auth, need to change to make it work?

My specific error message is on #7561, which is marked as duplicate to this issue.

Was this page helpful?
0 / 5 - 0 ratings