Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#29516 closed Cleanup/optimization (fixed)

Rephrase error message when passing incorrect kwarg to model constructor

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

Description

When passing an incorrect keyword argument to a model constructor, the init method will throw an error like this:

TypeError: 'x' is an invalid keyword argument for this function

It takes a couple of seconds to notice what "this function" refers to, especially if the call is behind some abstraction like factory_boy. You have to scroll several levels up the stack trace to notice the offender. I propose to change this message to:

TypeError: 'x' is an invalid keyword argument for ModelName

I can submit a pull request once the ticket is accepted.

Change History (6)

comment:1 by Federico Bond, 7 years ago

Perhaps even better would be to imitate the default error message in Python:

ModelName() got an unexpected keyword argument 'x'

comment:2 by Tim Graham, 7 years ago

Component: Error reportingDatabase layer (models, ORM)
Owner: set to nobody
Summary: Improve error message when passing incorrect kwarg to model constructorRephrase error message when passing incorrect kwarg to model constructor
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

comment:3 by Federico Bond, 7 years ago

Owner: changed from nobody to Federico Bond
Status: newassigned

comment:4 by Federico Bond, 7 years ago

Has patch: set
Last edited 7 years ago by Tim Graham (previous) (diff)

comment:5 by Claude Paroz, 7 years ago

Resolution: fixed
Status: assignedclosed

In 4c36414:

Fixed #29517 -- Rephrased error message when passing incorrect kwarg to model constructor

comment:6 by Tim Graham <timograham@…>, 7 years ago

In e7185a6:

Refs #29516 -- Reverted inadvertent change in Model.init().

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