#36158: `get_and_report_namespace` incorrectly reports the location where an object
was created.
-------------------------------------+-------------------------------------
Reporter: Salvo | Owner: Salvo Polizzi
Polizzi |
Type: Bug | Status: assigned
Component: Core | Version: dev
(Management commands) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When `get_and_report_namespace` is called with `verbosity=2`, it
misreports the actual location where an object was created. This seems to
happen because the function only considers objects with a `__module__`
attribute. While this works correctly for functions and classes (which are
defined in a module), it fails for instances. Since instances can be
created elsewhere, the function incorrectly reports the module where the
class was defined rather than where the instance was created.
== Steps to reproduce
1. Override `get_namespace()` using this
[
https://docs.djangoproject.com/en/dev/howto/custom-shell/#customizing-
shell-auto-imports tutorial] as follows:
{{{
from django.core.management.commands import shell
class Command(shell.Command):
def get_namespace(self):
from django.db import connection
return {
"connection": connection,
}
}}}
2. Start the Django shell with:
{{{
python manage.py shell -v 2
}}}
3. The output should report:
{{{
1 objects imported automatically, including:
from django.utils.connection import connection
}}}
However, this is incorrect because connection is an instance, and it
should report where it was actually created, not just the module where its
class was defined.
--
Ticket URL: <
https://code.djangoproject.com/ticket/36158>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.