Opened 2 years ago

Closed 2 years ago

#17527 closed Cleanup/optimization (fixed)

Better TypeError: m2m.add(wrong_type)

Reported by: guettli 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 guettli 2 years ago.
17527-2.diff (3.1 KB) - added by claudep 2 years ago.
Patch with tests

Download all attachments as: .zip

Change History (6)

Changed 2 years ago by guettli

comment:1 Changed 2 years ago by claudep

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 2 years ago by claudep

Patch with tests

comment:2 Changed 2 years ago by claudep

  • 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 2 years ago by guettli

  • Triage Stage changed from Accepted to Ready for checkin

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

comment:4 Changed 2 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

In [17437]:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.