Opened 7 years ago

Closed 7 years ago

#29320 closed Bug (fixed)

Add an exception when an annotation alias matches a ForeignKey attname

Reported by: Flávio Juvenal Owned by: Flávio Juvenal
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: no UI/UX: no

Description (last modified by Flávio Juvenal)

Looks like the solution for "#11256 Fail loudly and clearly when an Annotation alias matches a field name" doesn't consider foreign keys attnames, e.g. author_id.

Here's a failing test, add it to aggregation_regress/tests.py:

def test_fk_attname_conflict(self):
    msg = "The annotation 'contact_id' conflicts with a field on the model."
    with self.assertRaisesMessage(ValueError, msg):
        Book.objects.annotate(contact_id=F('publisher_id'))

PR here: https://github.com/django/django/pull/9873/files

Change History (4)

comment:1 by Flávio Juvenal, 7 years ago

Description: modified (diff)
Owner: changed from Flávio Juvenal to Flávio Juvenal

comment:2 by Flávio Juvenal, 7 years ago

Description: modified (diff)

comment:3 by Tim Graham, 7 years ago

Summary: No exception when an Annotation alias matches a ForeignKey attnameAdd an exception when an annotation alias matches a ForeignKey attname
Triage Stage: UnreviewedReady for checkin

comment:4 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In e1f13f15:

Fixed #29320 -- Added an exception when an annotation alias matches a ForeignKey attname.

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