Opened 8 years ago

Last modified 8 years ago

#27720 closed Cleanup/optimization

Confusing error message when creating a model with unspecified attributes that have no defaults — at Initial Version

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

Using the example project at https://docs.djangoproject.com/en/1.10/intro/tutorial02/.

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

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

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

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 isnt related to the initial error.

Change History (0)

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