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

Unable to Import Mix-in Classes independently of package #36

Closed
jambonrose opened this issue Sep 1, 2017 · 7 comments
Closed

Unable to Import Mix-in Classes independently of package #36

jambonrose opened this issue Sep 1, 2017 · 7 comments
Projects

Comments

@jambonrose
Copy link
Contributor

Specifications

  • Platform/System: macOS 10.11
  • Python Version: 3.6
  • Django Version: 1.11
  • Improved User Version: 0.5.3

Expected Behavior

In a Django project: I expect to be able to import the mix-in model classes without needing to add improved_user to INSTALLED_APPS.

Actual Behavior

Django evaluates the User model and attempts to add it to the database.

  File "/Users/andrew/Development/verified-auth/.tox/py36-django111-unit/lib/python3.6/site-packages/verified_auth/models.py", line 7, in <module>
    from improved_user.models import (
  File "/Users/andrew/Development/verified-auth/.tox/py36-django111-unit/lib/python3.6/site-packages/improved_user/models.py", line 167, in <module>
    class User(AbstractUser):
  File "/Users/andrew/Development/verified-auth/.tox/py36-django111-unit/lib/python3.6/site-packages/django/db/models/base.py", line 118, in __new__
    "INSTALLED_APPS." % (module, name)
RuntimeError: Model class improved_user.models.User doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

Context

I am using the provided mix-in classes and manager to create a new User model in a separate app.

from django.contrib.auth.models import (
    AbstractBaseUser, PermissionsMixin,
)
from django.db import models
from django.utils.translation import ugettext_lazy as _
from improved_user.models import (
    DjangoIntegrationMixin, EmailAuthMixin, UserManager,
)

The import above causes the traceback listed above.

If I add improved_user to INSTALLED_APPS I believe Django will pollute my database with a table for User, which I am seeking to replace.

Steps to Reproduce the Problem

  1. Create a new Django project with a new Django app
  2. Install django-improved-user==0.5.3
  3. Import the tools (as seen in the code above)
  4. Run migrations or tests to cause the RunTimeError
@jambonrose jambonrose added this to To Do in Version 1.0 Sep 30, 2017
@jambonrose jambonrose moved this from To Do to In Progress in Version 1.0 Oct 1, 2017
@securedirective
Copy link
Contributor

I concur with this issue. I just ran into it myself and was about to email you to see if perhaps I was doing something wrong.

Is there any currently working way of extending django-improved-user as the documentation implies?

@jambonrose
Copy link
Contributor Author

Not currently, but I am planning to fix the issue tomorrow!

@jambonrose
Copy link
Contributor Author

.... ok, that's not quite true.

You can use all the mix-ins if you add the app to INSTALLED_APPS. The catch is that you will end up with an extra model (the improved user) in your database. As long as you don't point the user model setting to the improved user, and instead point it to your own User, you won't be introducing any long term problems. In theory, once the next version is out, you'll be able to simply remove the app from INSTALLED_APPS, and migrations will take care of the rest (in theory -I have not tested this!).

@securedirective
Copy link
Contributor

Nope. I've followed your documentation as closely as I can and I only get errors from Django, even on a fresh project. Would you like me to write up a separate bug report describing what I see, even prior to your new version?

I'm hoping this is just a documentation+newbie problem. :)

@jambonrose
Copy link
Contributor Author

Oh, there's definitely a problem, so even following documentation, I expect that it'd be difficult to get around this bug.

The branch I just pushed appears to fix the problem. Unfortunately, it's not quite ready to be integrated into the main branch, because these changes completely break the documentation.

The example_extension_project directory on the fix_issue_36_move_model_mixins branch should prove to be a guide for how to build a new User model from this new code. I'm planning to fix the documentation and add new documentation on this subject tomorrow.

Let's hold off on opening a new bug report for the moment. If you are still seeing errors once I merge the fix_issue_36_move_model_mixins branch in, then I welcome a new issue. Thanks!

@securedirective
Copy link
Contributor

securedirective commented Oct 8, 2017 via email

@jambonrose
Copy link
Contributor Author

jambonrose commented Oct 8, 2017

@securedirective: take a look at the new documentation found in here. Let me know what you think!

For the moment, to use the new code, you'll need to install the code directly from github (the development branch).

If you are still seeing an error that reads RuntimeError: Model class improved_user.models.User doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS., please reopen this issue and describe how you got the error. If you are seeing a different error, please open a new issue.

Thanks for all your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

2 participants