Opened 7 years ago
Last modified 5 years ago
#30300 closed New feature
Allow migrations directories without __init__.py files — at Version 5
| Reported by: | Benjy Weinberger | Owned by: | Benjy Weinberger |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 3.1 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Background: In python 3 a package with no __init__.py is implicitly a namespace package, so it has no __file__ attribute.
The migrate command currently checks for existence of a __file__ attribute on the migrations package. This check was introduced in #21015, because the __file__ attribute was used in migration file discovery.
However, in #23406 migration file discovery was changed to use pkgutil.iter_modules (), instead of direct filesystem access. pkgutil. iter_modules() uses the package's __path__ list, which exists on implicit namespace packages.
As a result, the __file__ check is no longer needed, and in fact prevents migrate from working on namespace packages (implicit or otherwise).
Related work: #29091
Change History (5)
comment:1 by , 7 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:2 by , 7 years ago
comment:3 by , 7 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Type: | Bug → New feature |
Hi Benjy. Thanks for the report — and the test case in the PR! Unless something comes up in review, this seems reasonable to me.
I'm going to call it a new feature, since this behaviour will never have worked I think.
... (implicit or otherwise)
I don't quite follow the or otherwise there?
comment:4 by , 7 years ago
| Summary: | migrate silently ignores apps whose migrations directory doesn't have an __init__.py → Allow migrations directories without __init__.py files. |
|---|
comment:5 by , 7 years ago
| Description: | modified (diff) |
|---|---|
| Summary: | Allow migrations directories without __init__.py files. → Allow migrations directories without __init__.py files |
What's the use case? When makemigrations generates the first migration, it adds an __init__.py file. There was some concern about encouraging namespace packages in ticket:23919#comment:102.
Proposed fix in https://github.com/django/django/pull/11141
(branch https://github.com/benjyw/django/tree/ticket_30300)/