Opened 5 years ago

Closed 5 years ago

#31310 closed Cleanup/optimization (fixed)

Wrong hint about recursive relationship.

Reported by: Matheus Cunha Motta Owned by: Matheus Cunha Motta
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Matheus Cunha Motta)

When there's more than 2 ForeignKeys in an intermediary model of a m2m field and no through_fields have been set, Django will show an error with the following hint:

hint=(
    'If you want to create a recursive relationship, '
    'use ForeignKey("%s", symmetrical=False, through="%s").'

But 'symmetrical' and 'through' are m2m keyword arguments, not ForeignKey.

This was probably a small mistake where the developer thought ManyToManyField but typed ForeignKey instead. And the symmetrical=False is an outdated requirement to recursive relationships with intermediary model to self, not required since 3.0. I'll provide a PR with a proposed correction shortly after.

Edit: fixed description.

Change History (7)

comment:1 by Matheus Cunha Motta, 5 years ago

Here's a PR: https://github.com/django/django/pull/12497

Edit: forgot to run tests and there was an error detected in the PR. I'll try to fix and run tests before submitting again.

Last edited 5 years ago by Matheus Cunha Motta (previous) (diff)

comment:2 by Matheus Cunha Motta, 5 years ago

Description: modified (diff)

comment:3 by Simon Charette, 5 years ago

Has patch: set
Triage Stage: UnreviewedAccepted

comment:4 by Mariusz Felisiak, 5 years ago

Needs tests: set
Owner: changed from nobody to Matheus Cunha Motta
Status: newassigned
Summary: Wrong hint about recursive relationshipWrong hint about recursive relationship.
Version: 3.0master

comment:5 by Mariusz Felisiak, 5 years ago

Needs tests: unset
Triage Stage: AcceptedReady for checkin

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 308fab92:

Refs #31310 -- Added test for check for using intermediate model with ambiguous foreign key from model.

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In e908eb6:

Fixed #31310 -- Fixed hints in checks for using intermediate model with ambiguous foreign key.

symmetrical=False is not required since
87b1ad6e7351464c60e751b483d9dfce3a2d3382.

Note: See TracTickets for help on using tickets.
Back to Top