﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
14087	django.core.management.get_commands only sees commands in the last package of a namespace package	KyleMac	nobody	"If using the namespace features of setuptools, then get_commands will only see the commands in the last package. If you have something like the following:

{{{
company.app1.management.commands.command1
company.app2.management.commands.command2
}}}

then Django will only spot command2. I don't know what the proper fix would be, but I use the following to fill in the gaps:

{{{
def find_namespace_commands():
    try:
        from django.conf import settings
        apps = settings.INSTALLED_APPS
    except (AttributeError, EnvironmentError, ImportError):
        apps = []
    import imp
    from django.core.management import _commands, find_commands
    from django.utils.importlib import import_module
    for app in apps:
        try:
            app_path = import_module(app).__path__
        except AttributeError:
            continue
        try:
            imp.find_module('management', app_path)
        except ImportError:
            continue
        mod = import_module('%s.management' % app)
        if hasattr(mod, '__path__'):
            for cmd in find_commands(mod.__path__[0]):
                if _commands is None:
                    _commands = {}
                if cmd not in _commands:
                    _commands[cmd] = app


find_namespace_commands()
}}}
"	Bug	closed	Core (Other)	dev	Normal	fixed		Johannes Bornhold David Reynolds lnielsen@… bhuztez alex@… daevaorn@… Nicola	Accepted	0	0	0	0	0	0
