Opened 5 years ago

Last modified 5 years ago

#31310 closed Cleanup/optimization

Wrong hint about recursive relationship — at Version 2

Reported by: Matheus Cunha Motta Owned by: nobody
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 (2)

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)
Note: See TracTickets for help on using tickets.
Back to Top