Skip to content

Handling of Django >= 1.5 custom user model broken in 0001_initial.py #264

@ramiro

Description

@ramiro

Commit f4ea1fd introduced compatibility with the new custom user. Later fixed to be compatible with Django < 1.5 in b4f7e0c.

But one problem is that it blindly puts the custom user model in the frozen ORM section of the migration and so the final description of the model is one pointing to the developer's custom user model but that has the fields of django.contrib.auth.models.User (!):

"%s.%s" % (User._meta.app_label, User._meta.module_name): {
'Meta': {'object_name': User.__name__, "db_table": "'%s'" % User._meta.db_table},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},

    "%s.%s" % (User._meta.app_label, User._meta.module_name): {
        'Meta': {'object_name': User.__name__, "db_table": "'%s'" % User._meta.db_table},
        'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
        'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
        'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
        'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
        'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
        'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
        'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
        'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
        'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
        'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
        'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
        'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
        'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
      },

This is wrong. Unfortunately I don't have a solution and I'm not sure if there is actually one.

Found this when researching a solution for a

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

error when running the migrations for a non-trivial project that included django-reversion. The error is triggered by the import-time call to get_user_model() at the top of the migration.

When South reloads the migrations (among them django-reversion's) that function fails reporting it can't find the custom user model although it's actually on the Django app/model cache, which would suggest a circular import problem.

IMHO there It would be good if a solution similar to 798cc8b could be applied to the migration file and so avoid having an import-time get_user_model() call.

See also:

dabapps/django-user-roles#6
https://github.com/caffeinehit/django-oauth2-provider/pull/18/files

But that is another issue that will be possibly reason for another ticket.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions