#9751 closed (fixed)
project_directory calculated incorrectly when "settings" is a directory (breaks 'startapp')
Reported by: | Chris Lamb | Owned by: | George Song |
---|---|---|---|
Component: | Core (Management commands) | Version: | 1.0 |
Severity: | Keywords: | startapp, settings, module | |
Cc: | robillard.etienne@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When a Django project's settings is contained in directory-style module instead of the usual "settings.py
" file-based module, project_directory
(as returned from setup_environ) is calculated incorrectly as "settings
", which results in--at least--'startapp
' creating new apps inside the settings directory.
Whilst the use of a settings directory is non-standard, it helps when splitting larger or more complicated configurations, such as when settings change depending on the hostname, etc. Indeed, this would be completely transparent to Django if it wasn't parsing the __file__
attribute.
To reproduce:
% django-admin.py startproject myproject % cd myproject % mkdir settings % mv settings.py settings/__init__.py % ./manage.py startapp myapp % tree |-- __init__.py |-- manage.py |-- settings | |-- __init__.py | `-- myapp # <---- | |-- __init__.py | |-- models.py | `-- views.py `-- urls.py Patch attached.
Attachments (4)
Change History (20)
by , 16 years ago
Attachment: | 0001-Fix-project_name-location-when-settings-is-a-module.patch added |
---|
by , 16 years ago
Attachment: | 06-fix-project_name-location-when-settings-is-a-module.patch added |
---|
0001-Fix-project_name-location-when-settings-is-a-module.patch
comment:2 by , 16 years ago
milestone: | → 1.1 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 16 years ago
Component: | Uncategorized → django-admin.py |
---|
comment:4 by , 16 years ago
06-fix-project_name-location-when-settings-is-a-module.patch does fix the bug. It also breaks 37 of the admin_scripts regression tests. Somehow it causes the spawned admin commands to die with a "TypeError: relative imports require the 'package' argument" traceback.
comment:5 by , 16 years ago
Looks like the conditional the patch added (if settings_name == "init") is being excecuted during the tests, even though I don't think they are using a settings directory. Not exactly sure why that is.
by , 16 years ago
Attachment: | 9751-core_management_init-r10599.diff added |
---|
comment:6 by , 16 years ago
My patch fixes a few problems:
get_commands()
was importing project settings each time it's called. That's not necessary.
get_commands()
was actually passing the project package instead of settings module/package to
setup_environ()
.
- In
setup_environ()
, check to see if settings module is a package or module by checking to see if its
file
contains
init.py
or not. Not sure if this works for Jython as I don't know how Jython filenames work.
comment:7 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
by , 16 years ago
Attachment: | 9751-with-tests.diff added |
---|
Basic patch, removed the sys.modules import, and it seems to work without all that split() stuff, but if there's a reason that was there, feel free to add it back.
comment:9 by , 16 years ago
All tests pass, and the regression test (first at the top of that patch) fails on current trunk and passes with the patch.
comment:10 by , 16 years ago
Needs tests: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
comment:11 by , 16 years ago
The reason for using sys.modules
lookup instead of import_module()
was to prevent the setting module from unnecessarily being imported again, since it would have to have been imported by this point.
comment:13 by , 16 years ago
Cc: | added |
---|
comment:14 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Rebasing patch against HEAD