Management can't load custom commands when separately packaged apps share a common base module
|Reported by:||nOw2||Owned by:||nobody|
|Component:||Core (Management commands)||Version:||1.4|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Description (last modified by ramiro)
django.core.management.find_management_module() loads custom commands for manage.py by finding the path of the module and examining file directly.
This fails when apps are within packages that share a common base name, but where the files are NOT in the same directories, example:
- app 1: company.division.project_a.app1 stored in path packages/company.subdivision.project_a.app1
- app 2: company.division.project_b.app2 stored in path packages/company.subdivision.project_b.app2
Custom commands in app 2 will not be found.
A code trace from pdb follows. Excuse the rather complicated example, but this is from a genuine problem and only the modules names have been changed.
> site-packages/django/core/management/__init__.py(43)find_management_module() -> parts.append('management') (Pdb) parts ['company', 'subdivision', 'project_b', 'app2'] . . . > site-packages/django/core/management/__init__.py(62)find_management_module() -> f, path, descr = imp.find_module(part, path and [path] or None) (Pdb) ImportError: 'No module named project_b' > site-packages/django/core/management/__init__.py(62)find_management_module() -> f, path, descr = imp.find_module(part, path and [path] or None) (Pdb) l 57 if os.path.basename(os.getcwd()) != part: 58 raise e 59 60 while parts: 61 part = parts.pop() 62 -> f, path, descr = imp.find_module(part, path and [path] or None) 63 return path 64 65 def load_command_class(app_name, name): 66 """ 67 Given a command name and an application name, returns the Command (Pdb) part 'project_b' (Pdb) path 'packages/company.subdivision.project_a.app1/company/subdivision'
Issue was found in 1.3.1 but the code appears the same in the current trunk version:
Change History (5)
comment:1 Changed 2 years ago by anonymous
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Type changed from Uncategorized to Bug
comment:3 Changed 22 months ago by andrewgodwin
- Resolution set to invalid
- Status changed from new to closed