#27720: Confusing error message when creating a model with unspecified
attributes
that have no defaults
-------------------------------------+-------------------------------------
Reporter: sanaani | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution: needsinfo
Keywords: model | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):
* status: new => closed
* resolution: => needsinfo
* type: Uncategorized => Cleanup/optimization
* easy: 1 => 0
Old 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 isn''t related to the initial error.
New 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 isn't related to the initial error.
--
Comment:
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/27720#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.67ab60fd6654040556b0e918ad04cd62%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.