[Django] #30300: migrate silently ignores apps whose migrations directory doesn't have an __init__.py

36 views
Skip to first unread message

Django

unread,
Mar 28, 2019, 3:06:03 PM3/28/19
to django-...@googlegroups.com
#30300: migrate silently ignores apps whose migrations directory doesn't have an
__init__.py
-------------------------------------+-------------------------------------
Reporter: Benjy | Owner: nobody
Weinberger |
Type: Bug | Status: new
Component: Database | Version: 2.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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
https://code.djangoproject.com/ticket/21015, because the `__file__`
attribute was used in migration file discovery.

However, in https://code.djangoproject.com/ticket/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: https://code.djangoproject.com/ticket/29091

--
Ticket URL: <https://code.djangoproject.com/ticket/30300>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 28, 2019, 3:06:24 PM3/28/19
to django-...@googlegroups.com
#30300: migrate silently ignores apps whose migrations directory doesn't have an
__init__.py
-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: Bug | Status: assigned
Component: Database layer | Version: 2.1
(models, ORM) |
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
-------------------------------------+-------------------------------------
Changes (by Benjy Weinberger):

* owner: nobody => Benjy Weinberger
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:1>

Django

unread,
Mar 28, 2019, 4:51:49 PM3/28/19
to django-...@googlegroups.com
#30300: migrate silently ignores apps whose migrations directory doesn't have an
__init__.py
-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: Bug | Status: assigned
Component: Database layer | Version: 2.1
(models, ORM) |
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 Benjy Weinberger):

Proposed fix in https://github.com/django/django/pull/11141
(branch https://github.com/benjyw/django/tree/ticket_30300)/

--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:2>

Django

unread,
Mar 29, 2019, 7:02:55 AM3/29/19
to django-...@googlegroups.com
#30300: migrate silently ignores apps whose migrations directory doesn't have an
__init__.py
-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: New feature | Status: assigned

Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* type: Bug => New feature
* stage: Unreviewed => Accepted


Comment:

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?

--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:3>

Django

unread,
Mar 29, 2019, 7:03:42 AM3/29/19
to django-...@googlegroups.com
#30300: Allow migrations directories without __init__.py files.

-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: New feature | Status: assigned
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:4>

Django

unread,
Mar 29, 2019, 10:29:25 AM3/29/19
to django-...@googlegroups.com
#30300: Allow migrations directories without __init__.py files
-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: New feature | Status: assigned
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Old description:

> 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
> https://code.djangoproject.com/ticket/21015, because the `__file__`
> attribute was used in migration file discovery.
>
> However, in https://code.djangoproject.com/ticket/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: https://code.djangoproject.com/ticket/29091

New description:

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

--

Comment (by Tim Graham):

What's the use case? When `makemigrations` generates the first migration,
it adds an `__init__.py` file.

--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:5>

Django

unread,
Mar 29, 2019, 1:52:26 PM3/29/19
to django-...@googlegroups.com
#30300: Allow migrations directories without __init__.py files
-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: New feature | Status: assigned
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Benjy Weinberger):

The "or otherwise" refers to namespace packages being either implicit
(lacking an __init__.py) or explicit (an __init__.py containing an old-
style namespace package incantation).

--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:6>

Django

unread,
Mar 29, 2019, 4:29:40 PM3/29/19
to django-...@googlegroups.com
#30300: Allow migrations directories without __init__.py files
-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: New feature | Status: assigned
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Benjy Weinberger):

Re the use case:

It seems unnecessary to insist on an empty `__init__.py` just to preserve
a (stale) check for `__file__`, when they are otherwise not required in
Python 3.

And https://code.djangoproject.com/ticket/29091 implies that this should
be allowed.

Context is: We've just finished migrating our codebase to all-python 3,
and nuked all our `__init__py` files. We are now upgrading to Django 2.1,
and noticing the various places where they're still de-facto required by
Django. This particular case seemed unnecessary and easy to fix.

--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:7>

Django

unread,
Apr 2, 2019, 3:51:33 AM4/2/19
to django-...@googlegroups.com
#30300: Allow migrations directories without __init__.py files
-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: New feature | Status: assigned
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Václav Řehák):

We had a similar issue with test discovery. One of our developers read an
article that `__init__.py` files are not required on Python3 and started
removing them. Everything seemingly worked but some tests were not
discovered and did not run in CI (which made it difficult to spot).

I think Django should not required them if technically possible or at
least it should be made clear in the documentation (sorry if I overlooked
it).

--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:8>

Django

unread,
Apr 23, 2019, 5:11:19 PM4/23/19
to django-...@googlegroups.com
#30300: Allow migrations directories without __init__.py files
-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: New feature | Status: assigned
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Benjy Weinberger):

Friendly nudge?

--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:9>

Django

unread,
Sep 24, 2019, 6:11:45 AM9/24/19
to django-...@googlegroups.com
#30300: Allow migrations directories without __init__.py files
-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: New feature | Status: assigned
Component: Database layer | Version: master

(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* has_patch: 0 => 1
* version: 2.1 => master


Comment:

[https://github.com/django/django/pull/11141 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:10>

Django

unread,
Oct 10, 2019, 2:53:14 AM10/10/19
to django-...@googlegroups.com
#30300: Allow migrations directories without __init__.py files
-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: New feature | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"3cd3bebe8921e14b911b36b2a1cbceef8fb6294e" 3cd3bebe]:
{{{
#!CommitTicketReference repository=""
revision="3cd3bebe8921e14b911b36b2a1cbceef8fb6294e"
Fixed #30300 -- Allowed migrations to be loaded from directories without
__init__.py file.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:11>

Django

unread,
Jul 19, 2020, 4:27:08 PM7/19/20
to django-...@googlegroups.com
#30300: Allow migrations directories without __init__.py files
-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

I raised this issue [https://groups.google.com/g/django-
developers/c/GVHMH2ciAnk/m/vbIPbZuSBQAJ on the mailing list] as there was
a thread that concluded that Django shouldn't promote use of implicit
namespace packages.

--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:12>

Django

unread,
Jul 21, 2020, 7:20:18 PM7/21/20
to django-...@googlegroups.com
#30300: Allow migrations directories without __init__.py files
-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: New feature | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: closed => new
* version: master => 3.1
* resolution: fixed =>
* severity: Normal => Release blocker


Comment:

Thus far there haven't been any mailing list replies in favor this change.
I created a [https://github.com/django/django/pull/13218 PR] to revert it
and modify the test accordingly.

--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:13>

Django

unread,
Jul 22, 2020, 1:04:28 AM7/22/20
to django-...@googlegroups.com
#30300: Allow migrations directories without __init__.py files
-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: New feature | Status: closed

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"ff55adbd0da6618abaf265d16196bf54f81aa77a" ff55adbd]:
{{{
#!CommitTicketReference repository=""
revision="ff55adbd0da6618abaf265d16196bf54f81aa77a"
Reverted "Fixed #30300 -- Allowed migrations to be loaded from directories
without __init__.py file."

This reverts commit 3cd3bebe8921e14b911b36b2a1cbceef8fb6294e.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:14>

Django

unread,
Jul 22, 2020, 1:05:28 AM7/22/20
to django-...@googlegroups.com
#30300: Allow migrations directories without __init__.py files
-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: New feature | Status: closed
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"d004bcee0c6c5558e524e2f5c75e3d70a119fd3d" d004bce]:
{{{
#!CommitTicketReference repository=""
revision="d004bcee0c6c5558e524e2f5c75e3d70a119fd3d"
[3.1.x] Reverted "Fixed #30300 -- Allowed migrations to be loaded from
directories without __init__.py file."

This reverts commit 3cd3bebe8921e14b911b36b2a1cbceef8fb6294e.
Backport of ff55adbd0da6618abaf265d16196bf54f81aa77a from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:15>

Django

unread,
Jul 22, 2020, 1:06:35 AM7/22/20
to django-...@googlegroups.com
#30300: Allow migrations directories without __init__.py files
-------------------------------------+-------------------------------------
Reporter: Benjy Weinberger | Owner: Benjy
| Weinberger
Type: New feature | Status: closed
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* resolution: fixed => wontfix
* stage: Accepted => Unreviewed


--
Ticket URL: <https://code.djangoproject.com/ticket/30300#comment:16>

Reply all
Reply to author
Forward
0 new messages