Opened 15 years ago

Last modified 10 years ago

#11264 closed

"from django.db import models" clobbered in functions inside __init__.py of installed apps — at Initial Version

Reported by: Antti Kaihola Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: importing
Cc: miracle2k Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If an app myapp has the following __init__.py:

from django.db import models
def myfunc():
    assert models.__package__ == 'django.db.models', (
        'models is %r instead of django.db.models' % models)

then calling myapp.myfunc() throws:

AssertionError:
  models is <module 'models_clobber_test_app.models' from 'myapp/models.pyc'>
  instead of django.db.models

This happens only if

  • myapp is in INSTALLED_APPS
  • myfunc is in myapp/__init__.py, not some other module in it
  • Django is r10088 or later (thanks, git bisect)

This breaks at least Satchmo from a few months back for me, probably trunk too.

r10088 claims to have fixed all dynamic imports in Django by backporting importlib from Python 2.7.

Change History (1)

by Antti Kaihola, 15 years ago

a minimal test project to reproduce "models" clobbering

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