Opened 12 months ago

Closed 12 months ago

Last modified 12 months ago

#23008 closed Bug (fixed)

Migrations depending on django.contrib.auth with custom User model fail

Reported by: semenov Owned by: nobody
Component: Migrations Version: 1.7-rc-1
Severity: Release blocker Keywords:
Cc: andrewgodwin, apollo13 Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Steps to reproduce:

  1. Create a new project and the new app accounts
  2. Create the model accounts.User:
    from django.contrib.auth import models as auth_models
    from django.db import models
    
    class User(auth_models.AbstractBaseUser, auth_models.PermissionsMixin):
            name = models.CharField(max_length=255, unique=True)
            USERNAME_FIELD = 'name'
    
  3. Edit settings.py and set AUTH_USER_MODEL = 'accounts.User'
  4. Run manage.py makemigrations accounts. It will crash:
    ...
      File "/Users/semenov/work/migrtest/venv/src/django/django/db/migrations/graph.py", line 42, in add_dependency
        raise KeyError("Dependency references nonexistent parent node %r" % (parent,))
    KeyError: u"Dependency references nonexistent parent node (u'auth', u'__last__')"
    

This started to happen 2 days ago, I bisected the cause to aba75e73db6a0baca1b721698ca24f026bb4a745 (the fix for #22970). Previously, the migration dependencies were set to [('auth', '__first__')] which worked fine. (I realize that __last__ makes more sense, so this is not about reverting the fix but rather making __last__ to work on django.contrib.auth.migrations.)

Change History (7)

comment:1 Changed 12 months ago by timo

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Bug

makemigrations works fine for me, it's not until migrate that I get the error.

comment:2 Changed 12 months ago by semenov

My bad, that's right, it's migrate that fails.

comment:3 Changed 12 months ago by timo

#23021 reported this for contenttypes.

comment:4 Changed 12 months ago by apollo13

  • Cc andrewgodwin apollo13 added

This seems to be caused by the fact that we have '__last__' and '__latest__'. (Changing the file to '__latest__' makes migrate work fine). @andrew: Which of the two did you intend in the beginning?

Last edited 12 months ago by timo (previous) (diff)

comment:5 Changed 12 months ago by andrewgodwin

Yeah, it's meant to be __latest__, error on my part in the fix for the previous bug. Will fix it tonight if nobody gets there first.

comment:6 Changed 12 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 9a2ab629776735fae2c9184dc4b9d9029bad15b2:

Fixed #23008 -- Fixed typo causing bad migration dependencies.

Thanks semenov for the report and Florian for investigation.

comment:7 Changed 12 months ago by Tim Graham <timograham@…>

In fe5f29eb1db795257d4095df0e1547c17daadade:

[1.7.x] Fixed #23008 -- Fixed typo causing bad migration dependencies.

Thanks semenov for the report and Florian for investigation.

Backport of 9a2ab62977 from master

Note: See TracTickets for help on using tickets.
Back to Top