#33272: Non-installed model error isn't raised if the module is in the 
submodule of
an installed app
-------------------------------------+-------------------------------------
     Reporter:  David Seddon         |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  closed
    Component:  Database layer       |                  Version:  3.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by David Seddon):

 Hi Carlton,

 I've looked at this in a bit more detail.

 From what I understand, `get_containing_app_config` is called to determine
 the containing app the first time a model is imported. If this happens
 during the bootstrap process (via models autodiscovery), then all well and
 good: the model gets registered as part of its containing app.

 The problem comes if an ''unregistered'' model class is inadvertently
 imported later as part of some runtime process. In this case it will go
 through the same registration process (but later than it should do),
 giving an inconsistent picture of which models are registered .We don't
 really want a model's registration to be triggered, say, by some incoming
 web request - or even just because running the webserver involves a larger
 import graph than running `manage.py makemigrations`.

 Ideally, the model registration process should be able to tell whether
 it's being called late. Might one option be for the
 [https://github.com/django/django/blob/main/django/db/models/base.py#L74
 model registration code] to insist on `apps.models_ready` being `False`
 before registering a model? (If it's `True`, it could raise a
 `RuntimeError`)?

 I don't believe this would get in the way of organizing models as packages
 (that's something we do a lot) as the models would still be registered
 during the bootstrap process.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33272#comment:5>
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 on the web visit 
https://groups.google.com/d/msgid/django-updates/066.af1c8805c42f61b7fb1d3604d7ae0d95%40djangoproject.com.

Reply via email to