Opened 13 years ago

Closed 13 years ago

#17527 closed Cleanup/optimization (fixed)

Better TypeError: m2m.add(wrong_type)

Reported by: Thomas Güttler Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: hv@… 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

Here is a small patch, to give a better error message, if you try to add a wrong type to a many to many field.

TypeError: 'Permission' instance expected, got <FooModel abc>

Attachments (2)

17527.patch (710 bytes ) - added by Thomas Güttler 13 years ago.
17527-2.diff (3.1 KB ) - added by Claude Paroz 13 years ago.
Patch with tests

Download all attachments as: .zip

Change History (6)

by Thomas Güttler, 13 years ago

Attachment: 17527.patch added

comment:1 by Claude Paroz, 13 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

by Claude Paroz, 13 years ago

Attachment: 17527-2.diff added

Patch with tests

comment:2 by Claude Paroz, 13 years ago

Needs tests: unset

While adding the tests, I realized there was too such similar exceptions. Mark it as RFC if you find my tests appropriate.

comment:3 by Thomas Güttler, 13 years ago

Triage Stage: AcceptedReady for checkin

I applied 17527-2.diff and all unittests pass on current SVN trunk. Ready for checkin. Thank you claudep

comment:4 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: newclosed

In [17437]:

Fixed #17527 -- Improved exception message when adding the wrong type of object to a ManyToManyField. Thanks, guettli and cClaude Paroz.

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