#25109: MigrationLoader.load_disk hides ImportError for invalid 
MIGRATION_MODULES
----------------------------+--------------------
     Reporter:  blueyed     |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Migrations  |    Version:  master
     Severity:  Normal      |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+--------------------
 With an invalid module name in `MIGRATION_MODULES`, you will get a rather
 confusing `InvalidBasesError`:

 {{{
 InvalidBasesError: Cannot resolve bases for [<ModelState:
 'djangocms_text_ckeditor.Text'>]
 This can happen if you are inheriting models from an app with migrations
 (e.g. contrib.auth)
  in an app with no migrations; see
 https://docs.djangoproject.com/en/1.8/topics/migrations/#dependencies for
 more
 }}}

 This is caused by ignoring the `ImportError` in
 
https://github.com/django/django/blob/d72f8862cb1a39934952e708c3c869be1399846e/django/db/migrations/loader.py#L70-L78,
 which is meant to handle non-existent migrations.

 The following patch might fix it:

 {{{
 diff --git i/django/db/migrations/loader.py
 w/django/db/migrations/loader.py
 index a8f4be4..e872294 100644
 --- i/django/db/migrations/loader.py
 +++ w/django/db/migrations/loader.py
 @@ -72,7 +72,9 @@ def load_disk(self):
              except ImportError as e:
                  # I hate doing this, but I don't want to squash other
 import errors.
                  # Might be better to try a directory check directly.
 -                if "No module named" in str(e) and MIGRATIONS_MODULE_NAME
 in str(e):
 +                if ("No module named" in str(e)
 +                        and MIGRATIONS_MODULE_NAME in str(e)
 +                        and app_config.label not in
 settings.MIGRATION_MODULES):
                      self.unmigrated_apps.add(app_config.label)
                      continue
                  raise
 }}}

 But then Django's tests itself fail, because they use this "hack":

 {{{
     settings.MIGRATION_MODULES = {
         # these 'tests.migrations' modules don't actually exist, but this
 lets
         # us skip creating migrations for the test models.
         'auth': 'django.contrib.auth.tests.migrations',
         'contenttypes': 'contenttypes_tests.migrations',
     }
 }}}
 
([Source](https://github.com/django/django/blob/d72f8862cb1a39934952e708c3c869be1399846e/tests/runtests.py#L142-147))

 I've seen this issue multiple times in the context of Django CMS (and its
 plugins), because in the progress of migrating to Django's migrations they
 were using modules like `djangocms_text_ckeditor.migrations_django` which
 then were renamed.

--
Ticket URL: <https://code.djangoproject.com/ticket/25109>
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/050.69b5b0b56e41b9f2a8931fbb4752ee49%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to