#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 <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/064.65a4f40672136cb228162955c9453a78%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to