Leaklens

django__django-12325

pk setup for MTI to parent get confused by multiple OneToOne references.

Verdict: disputed: one of the two checks found quoted evidence (not counted as a flag).

We can extend key logic with related_name, e.g ('app', 'document', 'picking'). Or using this method, we can always ensure that the parent_link=True field is guaranteed into self.parents. ​PR +++ b/django/db/models/base.py @@ -196,10 +196,11 @@ class ModelBase(type): if base != new_class and not base._meta.abstract: continue # Locate OneToOneField instances. - for field in base._meta.local_fields: - if isinstance(field, OneToOneField): - related = resolve_relation(new_class, field.remote_field.model) - parent_links[make_model_tuple(related)] = field + fields = [field for field in base._meta.local_fields if isinstance(field, OneToOneField)] + for field in sorted(fields, key=lambda x: x.remote_field.parent_link, reverse=True): + related_key = make_model_tuple(resolve_relation(new_class, field.remote_field.model)) + if related_key not in parent_links: + parent_links[related_key] = field

Disputed: one of the two checks found a stated fix, the other found nothing. Not counted as a flag; the quote is on the task page.

All SWE-bench Verified tasks · more django/django tasks · How the check works