#26186: When extending from abstract model, ForeignKey points to wrong 
application
-------------------------------------+-------------------------------------
     Reporter:  skyjur               |                    Owner:  charettes
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  1.9
  (models, ORM)                      |
     Severity:  Release blocker      |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by charettes):

 * status:  new => assigned
 * owner:  nobody => charettes
 * severity:  Normal => Release blocker
 * stage:  Unreviewed => Accepted


Comment:

 Well I stand corrected. It looks like the reported behavior is possible as
 long as the application containing the abstract module is not yet
 imported.

 Here's what happens on '''Django 1.8'''.

 The `b` application is imported by the app loading mechanism and triggers
 and the import of `a.abstract`. At this point the abstract models are not
 bound to any application and thus the `AbstractModel2.model1` field is not
 resolved to any model which allows the `b.Model2.model1` field to resolves
 to `b.Model1`. When the `a` application is loaded the abstract models are
 bound to it (because they are defined in a `a` submodule) and thus
 `a.Model2` automatically resolves to `a.Model1`.

 In this case if the `a` application is loaded before the `b` application
 `b.Model2` will point to `a.Model1` because the abstract models were bound
 to the `a` application when `b.models` will import `a.abstract` (which was
 imported by `a.models` first).

 Here's what happen before #25858 was fixed ('''1.9, 1.9.1'''):

 App relative lazy relationships defined on abstract models were never
 resolved thus the behavior described above if the `b` application appeared
 before the `a` one on Django `1.8` was always present and not dependent on
 `ÌNSTALLED_APPS` ordering.

 Here's what happen since #25858 is fixed ('''1.9.2''' , '''master'''):

 It's not possible anymore as app relative lazy relationships defined on
 abstract models are bound to the application in which they are defined.

 I'll take this to the ML again to gather feedback but I'm inclined to
 close this as ''wontfix'' because the behavior was only achievable in 1.8
 through import side effects.

--
Ticket URL: <https://code.djangoproject.com/ticket/26186#comment:8>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.bb360c9b039dc718c768af225f2fd544%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to