#36864: Automatic shell imports cannot reliably handle submodules
-------------------------------------+-------------------------------------
     Reporter:  Jacob Walls          |                    Owner:  Leland
                                     |  Boeman
         Type:  Bug                  |                   Status:  assigned
    Component:  Core (Management     |                  Version:  5.2
  commands)                          |
     Severity:  Normal               |               Resolution:
     Keywords:  import_string,       |             Triage Stage:  Accepted
  submodule                          |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Leland Boeman):

 I realized I missed that in #35402
 
https://github.com/django/django/blob/main/django/db/backends/base/creation.py#L378-L387
 an except block was added to handle this bug.


 {{{
             except ImportError:
                 # import_string() can raise ImportError if a submodule's
 parent
                 # module hasn't already been imported during test
 discovery.
                 # This can happen in at least two cases:
                 # 1. When running a subset of tests in a module, the test
                 #    runner won't import tests in that module's other
                 #    submodules.
                 # 2. When the parallel test runner spawns workers with an
 empty
                 #    import cache.
                 test_to_mark = import_string(test_name)
                 test_frame = sys.modules.get(test_to_mark.__module__)
 }}}


 It looks like adopting this functionality would not break that code
 because any modules that don't exist would just result in a second
 ImportError being raised on the subsequent calls to
 import_string/sys.modules.get . But given that the behavior noted in the
 comments shouldn't occur if support for modules is added, should this
 except block be removed as to not cause confusion?
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36864#comment:10>
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/0107019e5699ba29-da86e3e6-4476-4e68-ae2d-2c5229876076-000000%40eu-central-1.amazonses.com.

Reply via email to