#28913: If MIGRATIONS_MODULES has a missing top-level package, proper error 
message
is not displayed
----------------------------+--------------------------------------
     Reporter:  oTree-org   |                    Owner:  nobody
         Type:  Bug         |                   Status:  new
    Component:  Migrations  |                  Version:  1.11
     Severity:  Normal      |               Resolution:
     Keywords:              |             Triage Stage:  Unreviewed
    Has patch:  0           |      Needs documentation:  0
  Needs tests:  0           |  Patch needs improvement:  0
Easy pickings:  0           |                    UI/UX:  0
----------------------------+--------------------------------------

Comment (by oTree-org):

 Sure, I attached a sample project. Try running "python manage.py
 makemigrations foo" to reproduce the error.

 Repro steps, from scratch:

 - python manage.py startapp "foo"
 - Add "foo" to INSTALLED_APPS
 - Add a simple model in foo/models.py
 - Set:
 {{{
 MIGRATION_MODULES = {'foo': 'nonexisting_dir'}
 }}}
 - Run "python manage.py makemigrations foo".

 Expected: this should trigger the following error explaining that the
 'nonexisting_dir' package is missing and needs to be created first (this
 error message already exists in the source code but is unreachable because
 of faulty exception handling):

 {{{
                 "Could not locate an appropriate location to create "
                 "migrations package %s. Make sure the toplevel "
                 "package exists and can be imported."
 }}}


 Actual result: uninformative error message

 {{{
 Traceback (most recent call last):
   File "C:\oTree\ve_dj11\lib\site-
 packages\django\core\management\commands\makemigrations.py", line 212, in
 write_migration_files
     migration_string = os.path.relpath(writer.path)
   File "C:\oTree\ve_dj11\lib\site-
 packages\django\db\migrations\writer.py", line 289, in path
     return os.path.join(self.basedir, self.filename)
   File "C:\oTree\ve_dj11\lib\site-
 packages\django\db\migrations\writer.py", line 256, in basedir
     base_module = import_module(".".join(existing_dirs))
   File
 
"C:\Users\wi\AppData\Local\Programs\Python\Python36-32\Lib\importlib\__init__.py",
 line 127, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
   File "<frozen importlib._bootstrap>", line 973, in _gcd_import
   File "<frozen importlib._bootstrap>", line 925, in _sanity_check
 ValueError: Empty module name
 }}}

 Without the proper error message, it's unclear how to fix the problem. I
 would not have guessed that the top-level package needs to exist; I would
 have expected "makemigrations foo" to create it for me.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28913#comment:2>
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/067.24c63ff80cbebbb5a720fc01ec7b5708%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to