Opened 5 years ago

Last modified 4 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 Tim Graham)

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 Benjy Weinberger, 5 years ago

Owner: changed from nobody to Benjy Weinberger
Status: newassigned

comment:3 by Carlton Gibson, 5 years ago

Triage Stage: UnreviewedAccepted
Type: BugNew 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 Carlton Gibson, 5 years ago

Summary: migrate silently ignores apps whose migrations directory doesn't have an __init__.pyAllow migrations directories without __init__.py files.

comment:5 by Tim Graham, 5 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.

Last edited 5 years ago by Tim Graham (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top