#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
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
So I tried adapting `BaseModel.__new__` to confirm this was effectively
never supported with
{{{#!diff
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 575365e11c..5a33f78a98 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -243,7 +243,17 @@ def __new__(cls, name, bases, attrs, **kwargs):
for field in base._meta.local_fields:
if isinstance(field, OneToOneField) and
field.remote_field.parent_link:
related = resolve_relation(new_class,
field.remote_field.model)
- parent_links[make_model_tuple(related)] = field
+ related_model_tuple = make_model_tuple(related)
+ if abstract and not any(
+ make_model_tuple(parent) == related_model_tuple
+ for parent in parents
+ if hasattr(parent, "_meta")
+ ):
+ raise TypeError(
+ "Abstract models must directly inherit from
parent "
+ "links they refer to."
+ )
+ parent_links[related_model_tuple] = field
# Track fields inherited from base models.
inherited_attributes = set()
}}}
And the suited failed on
[https://github.com/django/django/blob/47c837a1ff96ef1b10b44477a7a9f72283d12e83/tests/model_inheritance_regress/models.py#L37-L50
these models] which `git-blame` led me to #20883
(163a34ce4bc1086b346a52c7271f48d2c207f710) which makes me believe this
either never fully worked (notice the tests are very minimal) or that the
latest changes to abstract model inheritance field attribution in #24305
(85ef98dc6ec565b1add417bd76808664e7318026).
Given we have models in the suite I think we should at least bisect to
determine if this was ever properly supported but so minimally tested that
#24305 silently broke it. If it never truly worked then I'd suggest we add
this `TypeError` otherwise if it was broken by #24305 we should consider
it like a long standing regression.
--
Ticket URL: <https://code.djangoproject.com/ticket/36183#comment:4>
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/01070194fd1ab915-da16373c-3c82-41cd-874b-ff37beefc185-000000%40eu-central-1.amazonses.com.