Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#20344 closed Bug (duplicate)

Allow django to discover management commands from namespace packages.

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

Description

Certain third party package maintainers may desire to have their apps in a namespace package. If those packages contain management commands, Django might not be able to discover them.

For example, if you have a namespace package that looks something like this:

site-packages/namespace/space/package1
site-packages/namespace/space/package2

Django will not be able to discover the packages during management registration (and in fact, could raise errors depending on the management command). If Django fails to locate a package during this process, it fails silently, which could be confusing for some developers.

Package discovery fails for one primary reason:

  • 1. Namespace and namespace/space directories above do not necessarily need init.py files located in their directory.

So for demonstration, import namespace.space.package1 works while import namspace and import namespace.space will not work.

The workaround here is just to allow for a direct import (if it succeeds) and take the path from that module for django to register the management command.

This solution should work in most situations where the namespace package is installed "normally" and can be found in the python path.

Branch is here: https://github.com/eire1130/django/tree/namespace_management_imports
Commit is here: https://github.com/eire1130/django/commit/3d495addc567e617eaef2b107fea6edaad161288

If approved, I will send the pull request.

Change History (4)

comment:1 by Aymeric Augustin, 11 years ago

Isn't this a duplicate of #14087?

(IMO using namespace packages is just asking for trouble; I forbid their use; I'm at best -0 on this change.)

comment:2 by James Reynolds, 11 years ago

It does appear to be a dup, though I prefer my fix.

For what it's worth, I agree with you on namespace packages, but some of us need to use namespace packages for reasons that are out of control.

comment:3 by Karen Tracey, 11 years ago

Resolution: duplicate
Status: newclosed

in reply to:  2 comment:4 by bhuztez, 11 years ago

Cc: bhuztez@… added
Easy pickings: unset

Replying to eire1130:

It does appear to be a dup, though I prefer my fix.

For what it's worth, I agree with you on namespace packages, but some of us need to use namespace packages for reasons that are out of control.

the docstring says

Determines the path to the management module for the given app_name,
without actually importing the application or the management module.

obviously, your patch would import application module

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