#36158: get_and_report_namespace() incorrectly reports the location where an 
object
was created.
-------------------------------------+-------------------------------------
     Reporter:  Salvo Polizzi        |                    Owner:  Salvo
                                     |  Polizzi
         Type:  Bug                  |                   Status:  assigned
    Component:  Core (Management     |                  Version:  5.2
  commands)                          |
     Severity:  Release blocker      |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Salvo Polizzi):

 * has_patch:  0 => 1


Old description:

> 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.

New description:

 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#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070194caaff47f-ee72f7d0-b42c-4380-a47a-15767c363fce-000000%40eu-central-1.amazonses.com.

Reply via email to