Pull requests

#54 Declined
djm_ djm_
ubernostrum ubernostrum

Including Django 1.5's get_user_model at the module level causes import issues.

  1. djm_ avatardjm_

Hi James,

Firstly, thanks for your work on django-registration; I've been using it since 2009 and I've honestly lost track of the amount of time it has saved me over countless projects.

Secondly, this pull request relates more to the issue rather than the code itself; the code works and you are more than welcome to use it directly but I realise you might want to take a different path with it.

The problem: as it stands, registration/models.py includes a module level call to get_user_model if the method is available to import (as it would be when running against Django 1.5). Unfortunately, when using a custom defined auth model set in the normal way by using the app_name.model_name value for the AUTH_USER_MODEL setting, we can get circular import errors of the type:

"ImproperlyConfigured: AUTH_USER_MODEL refers to model 'users.User' that has not been installed"

This is due to how Django's app loading code currently works (I believe this is being worked on); calling get_user_model during initialisation before the custom user model has actually been loaded makes the whole thing explode.

The solution is to 1) lazy link Foreign Key fields by using strings instead of actual imports - this is recommended in the Django documentation & more importantly 2) to replace calls to User with run-time imports as opposed to init time imports.

NB: this only happens when you either include 'registration' in the INSTALLED_APPS setting or when you import from registration/models.py (e.g to subclass RegistrationProfile and swap out the Manager it uses).

Similar fixes can be seen in other projects:

django-tastypie: https://github.com/toastdriven/django-tastypie/pull/797#issuecomment-13618174 django-guardian: https://github.com/lukaszb/django-guardian/blob/master/guardian/compat.py#L27 django-filer: https://github.com/stefanfoulis/django-filer/pull/320

Happy to do any extra code tweaking or answer any questions on this.

Thanks James,


p.s If everyone else could please refrain from 'approving' or 'accepting' this pull request that would be cool, from past experience it does not help in any way except to spam James with emails and I've noticed a few declined pull requests over the whole 1.5 issue declined due to that. Cheers.

Comments (4)

    1. djm_ author

      Hi Michael,

      James has already made the call/design decision that the base views and forms will not work with custom user models as they are designed to work with the built in model and a custom model can't guarantee the correct logic. If you wish to use them, I believe the current suggestion is to subclass them and override for your own logic.

      This pull request is related to the location of the get_user_model call causing issues and that alone.


  1. Jorge C. Leitão

    Hi. I've been using this nice app.

    I recently start using it with django-authtools (custom auth models), and I had this same issue when using django-registration with django-authtools. In fact, this pull request makes both apps compatible:

    When using a custom auth model from django-authtools, after modifying what this pull request requests, it is possible to validade e-mails of custom users using django-registration.

    EDIT: As already pointed out, the form and views have to be made according to the auth user model used...

    1. djm_ author


      Please see this reply. James does not want to support what you suggest, judging by this FAQ entry.

      I'm using Django 1.5 and a custom user model; how do I make that work?

      Although the two built-in backends supplied with django-registration both assume Django's default User model, the base view classes are deliberately user-model-agnostic. Simply subclass them, and implement logic for your custom user model..

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.