Opened 6 years ago

Closed 5 years ago

#15669 closed New feature (fixed)

Include app label in admin validation messages

Reported by: Chris Lamb Owned by: gandalfar
Component: contrib.admin Version: master
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: yes

Description

It is possible to have duplicate model names across your project (which is a good thing). However, it currently results in some ambiguous error messages when validating admin classes.

For example:

'MembershipAdmin.raw_id_fields' refers to field 'user_id' that is missing from model 'Membership'.

... does that refer to my Membership class in my "foo" app or my "bar" app?

The attached patch includes the app label in the error messages. For example:

'MembershipAdmin.raw_id_fields' refers to field 'user_id' that is missing from model 'bar.Membership'.

Attachments (3)

01.diff (2.7 KB) - added by Chris Lamb 6 years ago.
ticket15669.diff (4.0 KB) - added by Jure Cuhalev <gandalf@…> 5 years ago.
Updated patch with tests
ticket15669_2.diff (8.9 KB) - added by Jure Cuhalev <gandalf@…> 5 years ago.
Updated patch so that modeladmin tests also pass. I also tried approach suggested by Alex and abandoned it because unicode() repr of model lowercases the model, making it harder to grep for errors.

Download all attachments as: .zip

Change History (12)

Changed 6 years ago by Chris Lamb

Attachment: 01.diff added

comment:1 Changed 6 years ago by Julien Phalip

Needs tests: set
Triage Stage: UnreviewedAccepted

Could you provide some tests for this?

comment:2 Changed 6 years ago by Luke Plant

Type: New feature

comment:3 Changed 6 years ago by Luke Plant

Severity: Normal

comment:4 Changed 5 years ago by Julien Phalip

UI/UX: set

comment:5 Changed 5 years ago by Jure Cuhalev <gandalf@…>

Easy pickings: unset
Owner: changed from nobody to anonymous
Status: newassigned

comment:6 Changed 5 years ago by Jure Cuhalev <gandalf@…>

Owner: changed from anonymous to gandalfar
Status: assignednew

Changed 5 years ago by Jure Cuhalev <gandalf@…>

Attachment: ticket15669.diff added

Updated patch with tests

comment:7 Changed 5 years ago by klette

Needs tests: unset
Triage Stage: AcceptedReady for checkin

comment:8 Changed 5 years ago by Alex Gaynor

You can simplify to unicode(model._meta) which makes this a bit shorter.

Changed 5 years ago by Jure Cuhalev <gandalf@…>

Attachment: ticket15669_2.diff added

Updated patch so that modeladmin tests also pass. I also tried approach suggested by Alex and abandoned it because unicode() repr of model lowercases the model, making it harder to grep for errors.

comment:9 Changed 5 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

In [16462]:

Fixed #15669 -- Included app label in admin validation messages. Thanks, lamby and Jure Cuhalev.

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