Opened 9 years ago

Closed 9 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


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 9 years ago.
17527-2.diff (3.1 KB) - added by Claude Paroz 9 years ago.
Patch with tests

Download all attachments as: .zip

Change History (6)

Changed 9 years ago by Thomas Güttler

Attachment: 17527.patch added

comment:1 Changed 9 years ago by Claude Paroz

Needs tests: set
Triage Stage: UnreviewedAccepted

Changed 9 years ago by Claude Paroz

Attachment: 17527-2.diff added

Patch with tests

comment:2 Changed 9 years ago by Claude Paroz

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 Changed 9 years ago by Thomas Güttler

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 Changed 9 years ago by Jannis Leidel

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