#36183: Model o2o inheritance with abstract models does not "evaluate" a lazy
relationship
-------------------------------------+-------------------------------------
     Reporter:  BeryCZ               |                    Owner:  (none)
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  5.1
  (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
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

 * resolution:   => invalid
 * status:  new => closed

Comment:

 Hello BeryCZ, thank you for this report. I've analyzed your models and I
 fear that the issue is the complex inheritance that you have proposed.
 Specifically, you cannot have a model (`ArticlePage`) that both inherits
 from `Page` and has a `OneToOneField` to `Page`. Without understanding
 your use case, it feels like a possible solution would be for your "pages"
 to have a FK to "page types" (instead of the other way around with the 1-1
 field).

 Your model definitions create an inheritance conflict:

 1. `AbstractPageType` expects a separate `Page` instance (this means every
 model that inherits from `AbstractPageType` must have a separate `Page`
 instance linked via the `page` field).
 2. `ArticlePage` is also inheriting `Page`, which means Django expects
 `ArticlePage` itself to be a `Page` instance.

 Django sees two competing ways to resolve `ArticlePage`:

 * `ArticlePage` is a `Page` (due to model inheritance), or
 * `ArticlePage` has a separate `Page` instance (due to the page
 `OneToOneField`).

 The error is caused because Django tries to retrieve the `mtime` field,
 which exists on `Page` (inherited via `AbstractPage`). But because
 `ArticlePage` also has a `OneToOneField` called `page`, Django gets
 confused about how to resolve `mtime`. Instead of treating `page` as a
 relationship to another `Page` instance, Django interprets it as a string.

 Solutions are either to remove the direct inheritance to `Page` or remove
 the `page` field from `AbstractPageType`.

 If you have further questions, there are several user support channels
 available. Please refer to TicketClosingReasons/UseSupportChannels for
 ways to get help.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36183#comment:1>
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/01070194faa5d6dc-ab1e7f40-f669-4c58-a14a-5e7b06ae7529-000000%40eu-central-1.amazonses.com.

Reply via email to