#24559: MigrationLoader.load_disk ImportError handling differs under py3/pypy vs
py2
----------------------------+--------------------
     Reporter:  kezabelle   |      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
----------------------------+--------------------
 Currently, within `load_disk`, the following happens:

 {{{
             try:
                 module = import_module(module_name)
             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):
                     self.unmigrated_apps.add(app_config.label)
                     continue
                 raise
 }}}

 However, the
 
[https://github.com/django/django/blob/2832a9b028c267997b2fd3dd0989670d57cdd08f/django/db/migrations/loader.py#L73
 if statement] behaves differently under pypy & python3, because the
 exception string is different.

 Under python2, the following yields
 {{{
 >>> from importlib import import_module
 >>> importlib('test_auth.migrations')
 ImportError: No module named test_auth.migrations
 }}}

 which would hit both parts of the conditional, and end up in
 `self.unmigrated_apps`

 However, under python3.3.3 the exception is:
 {{{
 ImportError: No module named 'test_auth'
 }}}
 and under pypy 2.2.1 (for python 2.7.3) the exception is:
 {{{
 ImportError: No module named test_auth
 }}}
 (same as py3k, sans quotes)

 Neither of these would end up `self.unmigrated_apps` because
 `MIGRATIONS_MODULE_NAME` doesn't appear in the string representation,
 though I suspect `import_module('testauthmigrations')` '''would''' work.

 I originally noticed this because of a [https://travis-ci.org/kezabelle
 /django-typesafetynet/builds/55545694 travis build] for a toy project, so
 it may not be a problem in practice, but it is at least inconsistent.

--
Ticket URL: <https://code.djangoproject.com/ticket/24559>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.53d132b4eb629a819f162cfbdfbf2062%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to