Opened 10 years ago

Closed 10 years ago

#22935 closed Bug (fixed)

Error message in ForeignKey.default_error_messages does not reflect the correct field when 'to_field' is used.

Reported by: ANUBHAV JOSHI Owned by: ANUBHAV JOSHI
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: anubhav9042@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If model be like

class Person(models.Model):
    name = models.CharField(max_length=30)
class Student(models.Model):
    per = models.ForeignKey(Person, to_field='name')

Now if invalid error comes up from validate(), it will be like
'person instance with pk 'somename' does not exist.'

It should be:
'person instance with name 'somename' does not exist.'

Change History (3)

comment:1 by ANUBHAV JOSHI, 10 years ago

Cc: anubhav9042@… added
Owner: changed from nobody to ANUBHAV JOSHI
Status: newassigned
Triage Stage: UnreviewedAccepted

I am marking this accepted as Tim and I found this out while working on some other ticket and he told me open a ticket for this and work on it.

comment:3 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 10e83d48a3b199f9c8c73882be1ded5016f86a1a:

Fixed #22935 -- Changed ForeignKey.default_error_messagesinvalid to refer to correct field.

Thanks Tim Graham for suggestion and review.

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