Opened 9 years ago

Closed 9 years ago

#21868 closed Bug (fixed)

Empty migrations dir causes exception

Reported by: lhn@… Owned by: Andrew Godwin <andrew@…>
Component: Migrations Version: dev
Severity: Normal Keywords:
Cc: info@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


]$ python migrate
Operations to perform:
  Synchronize unmigrated apps: admin, auth, contenttypes, sessions
  Apply all migrations: (none)
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
Installed 0 object(s) from 0 fixture(s)
Running migrations:
  No migrations needed.
Traceback (most recent call last):
  File "", line 10, in <module>
  File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/core/management/", line 427, in execute_from_command_line
  File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/core/management/", line 419, in execute
  File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/core/management/", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/core/management/", line 337, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/core/management/commands/", line 140, in handle
    changes = autodetector.changes(graph=executor.loader.graph)
  File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/db/migrations/", line 34, in changes
    changes = self._arrange_for_graph(changes, graph)
  File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/db/migrations/", line 312, in _arrange_for_graph
    if app_leaf is None and not self.questioner.ask_initial(app_label):
  File "/usr/lib/python3.3/site-packages/Django-1.7a1-py3.3.egg/django/db/migrations/", line 42, in ask_initial
    filenames = os.listdir(os.path.dirname(migrations_module.__file__))
AttributeError: 'module' object has no attribute '__file__'

Note: I'm using python3, not tested on python2

After deleting db.sqlite3 and all files in wishes/migrations and got the error above, when running migrate.
Deleting the same, plus the migrations directory solved the problem.

Change History (4)

comment:1 Changed 9 years ago by Markus Holtermann

Cc: info@… added
Triage Stage: UnreviewedAccepted

This happens if the directory exists but does not contain a file

comment:2 Changed 9 years ago by Carl Meyer

This happens because in Python 3.3+, is not required; a package without one is considered a namespace package (see PEP 420). Namespace packages do not have a __file__ attribute (it is not actually a required attribute for Python packages); they do have a __path__ attribute (which is a required attribute, and may potentially have more than one path on it).

See #17304 and #21862, and see for the approach app-loading is taking to this issue.

I think it would be best if migrations did not rely on __file__ but used __path__ instead. It could check if len(migrations_module.__path__) > 1 and raise an error in that case, like app-loading will.

comment:3 Changed 9 years ago by Carl Meyer

Type: UncategorizedBug

comment:4 Changed 9 years ago by Andrew Godwin <andrew@…>

Owner: set to Andrew Godwin <andrew@…>
Resolution: fixed
Status: newclosed

In 935e6c1dfc10808272bfda1bbda03bfee035f3dc:

Fixed #21868: Don't die when seeing py3 namespace packages for mig dirs

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