#23237: KeyError when upgrading to the new migrations system (related to git and
.pyc)
---------------------------------+----------------------------------
     Reporter:  hheimbuerger     |      Owner:  nobody
         Type:  Uncategorized    |     Status:  new
    Component:  Migrations       |    Version:  1.7-rc-2
     Severity:  Release blocker  |   Keywords:  git, pyc, migrations
 Triage Stage:  Unreviewed       |  Has patch:  0
Easy pickings:  0                |      UI/UX:  0
---------------------------------+----------------------------------
 There is a bit of an annoying gotcha connected to the upgrade path for the
 new migrations, git and the .pyc files. I would recommend to at least add
 this to the upgrade path docs at
 https://docs.djangoproject.com/en/dev/topics/migrations/#upgrading-from-
 south.

 Here's what happened:
 1. I followed the [https://docs.djangoproject.com/en/dev/topics/migrations
 /#upgrading-from-south upgrade path instructions] pretty much down to the
 letter: deleted my old South migration files, deleted the .pyc files, ran
 `makemigrations` and `migrate`. Everything worked fine and life was good.
 2. I committed these changes to my git repository. (Of course, I have
 `*.pyc` in my `.gitignore`.)
 3. My coworkers switched to my branch and upgraded to Django 1.7rc2.
 4. They ran `manage.py migrate` and got this:

 {{{
 System check identified no issues (0 silenced).
 Unhandled exception in thread started by <function wrapper at 0x03B75630>
 Traceback (most recent call last):
   File "c:\Python27\lib\site-packages\django\utils\autoreload.py", line
 222, in wrapper
     fn(*args, **kwargs)
   File "c:\Python27\lib\site-
 packages\django\core\management\commands\runserver.py", line 106, in
 inner_run
     self.check_migrations()
   File "c:\Python27\lib\site-
 packages\django\core\management\commands\runserver.py", line 158, in
 check_migrations
     executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
   File "c:\Python27\lib\site-packages\django\db\migrations\executor.py",
 line 17, in __init__
     self.loader = MigrationLoader(self.connection)
   File "c:\Python27\lib\site-packages\django\db\migrations\loader.py",
 line 48, in __init__
     self.build_graph()
   File "c:\Python27\lib\site-packages\django\db\migrations\loader.py",
 line 241, in build_graph
     self.graph.add_dependency(key, parent)
   File "c:\Python27\lib\site-packages\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'myapp',
 u'0001_initial')"
 }}}

 Obviously, the cause is that the `myapp/migrations/0001_initial.pyc` is
 still there, and while git replaced the `myapp/migrations/0001_initial.py`
 with the new migration one, the `myapp/migrations/0001_initial.pyc` is
 still the one from South. The error message is a bit weird, so it took us
 a few hours to figure out what's going on here.

 We had the same issue on three different coworkers' machines, all running
 some modern Windows (7–8), all running Python 2.7.4+ (32-bit) and
 SourceTree as the git client.

 ----

 I see three ways this could be tackled:

 First of all, a warning about this should probably be added to the upgrade
 path instructions, to at least save others from spending time to debug
 this.

 Second, the error message could probably be improved. Apparently, when
 trying to load the `myapp/migrations/0001_initial.pyc`, it detected that
 this wasn't a proper Django 1.7 migration file (correct) and just silently
 ignored it (not nice), later leading to that graph dependecy error. But
 why silently ignore this and not fail fast:
 "myapp/migrations/0001_initial.pyc is an invalid migration file!"

 Third, there's probably a way for the management command to actively
 detect stale bytecode caches, but that sounds fairly difficult to
 implement.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/23237>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/055.6e80a2eb2d2cf3013862da0b49216fdd%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to