#10337 closed (invalid)
syncdb fails to load initial_data with certain __init__.py
Reported by: | Torsten Bronger | Owned by: | nobody |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Keywords: | ||
Cc: | bronger@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If the application's __init__.py
contains
from django.contrib.auth import models
"manage.py syncdb
" doesn't load the init_data
fixture for this application.
import django.contrib.auth.models
doesn't cause this problem.
Change History (5)
comment:1 by , 16 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:2 by , 16 years ago
I can see why that would break something, but it's not something wrong with django, in python's import process when it sees from module import something the first place it checks is if that item exists in module/init.py, this isn't something Django could fix or work around or anything like that, it's just how python works.
comment:3 by , 16 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
I can reproduce it with the following steps:
django-admin.py startproject myproject
./manage.py startapp myapp
- Add a fixture called
initial_data
which e.g. simply adds a user inmyapp/fixtures/
- set the database settings in
settings.py
and add "myproject.myapp" toINSTALLED_APPS
- create the database in the database backend
- call syncdb. The fixture is loaded.
- Add myapp/init.py with the above mentioned line
- drop&create the database in the database backend
- call syncdb. The fixture is not loaded.
As to what Alex said, sorry but I don't understand it. Be that as it may, I don't see why a high-level functionality like fixture loading depends on how a module is loaded. Currently it does, but it needn't.
comment:4 by , 16 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
When python tries to import the models from your application so that it can instantiate them for the initial_data it's import includes the models path(obviously) however python import semantics say to look in the init of the app for the models name, therefore it can't ever find your applications models since it gets the models name from init which doesn't contain your models.
http://docs.python.org/reference/simple_stmts.html#the-import-statement
http://docs.python.org/library/functions.html#__import
comment:5 by , 16 years ago
Granted, but my application doesn't have models of its own anyway. myapp/models.py
is deliberately empty. Instead, the fixture adds "User
" instances from the auth module.
In other words, why does Django assume that a fixture only adds instances of the app's models? For example, User instances can be a very sensible thing to add.
I can't replicate this problem. I can't even think of a way that I _could_ replicate this problem - there isn't anything that should link the import method to initial_data fixtures.
If you can provide a complete set of instructions (or preferably, a full project definition) that demonstrates the problem, please reopen.