Opened 13 years ago

Last modified 13 years ago

#18179 closed Bug

Management can't load custom commands when separately packaged apps share a common base module — at Initial Version

Reported by: nOw2 Owned by: nobody
Component: Core (Management commands) Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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:
https://code.djangoproject.com/browser/django/trunk/django/core/management/__init__.py?rev=17842#L60

Change History (0)

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