Opened 7 years ago

Closed 7 years ago

#27720 closed Cleanup/optimization (needsinfo)

Confusing error message when creating a model with unspecified attributes that have no defaults

Reported by: sanaani Owned by: nobody
Component: Database layer (models, ORM) Version: 1.10
Severity: Normal Keywords: model
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

Using the example project at

The example project says to instantiate a model in this way:
q = Question(question_text="What's new?",

However, if you do something silly like not assigning attributes:
q = Question("What's new?",

The model will still instantiate. What's super confusing is that if you forget to type in the attributes, then apply

You get the bizarre error ValueError: invalid literal for int() with base 10: 'Question'

If a model object is created without an assigned attribute and the missing attribute has no default specified, then some type of warning should appear. I wasted about 3 hours today figuring out this dumb mistake; the error message isn't related to the initial error.

Change History (1)

comment:1 by Tim Graham, 7 years ago

Description: modified (diff)
Easy pickings: unset
Resolution: needsinfo
Status: newclosed
Type: UncategorizedCleanup/optimization

I'm not sure if a backwards-compatible solution is feasible. Objects created with the ORM assume the developer is doing things properly. If user input is incoming, then you can call Model.clean() to get a better error message. If someone has an idea of an improvement, feel free to reopen.

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