#17653: using id = 0 on get_or_create
-------------------------------------+-------------------------------------
Reporter: sylvain.lebon@… | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.3
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by krzysiumed):
* cc: krzysiumed@… (added)
* stage: Unreviewed => Accepted
Comment:
The same problem appears when you pass argument `id=0` to `__init__` of
your model (in my example it's `Text`), see code below.
{{{
>>> t = Text(id=0, text="lorem ipsum")
>>> t.id
0
>>> t.save()
>>> i.id
0
>>> Text.objects.all()
[<Text: Text object>]
>>> Text.objects.all()[0].id
1
}}}
The problem appears with `MySQL`. `sqlite3` works properly. I've not
checked other backends.
I think that the problem is in `django.db.models.fields.AutoField` which
is integer (see
https://docs.djangoproject.com/en/1.3/ref/models/fields/#autofield)
especially it can be zero. It should works like `PositiveIntegerField` or
something like that. Supporting `AutoField` validation can be a solution,
but it's backward incompatible. What's more, the validation is not
necessary for backends other than MySQL because zero is valid value for
`id` in most databases. We can check if `id` is not zero if the backend is
MySQL otherwise don't validate `id`, but it makes the issue more comlex
and it's still backward incompatible.
--
Ticket URL: <https://code.djangoproject.com/ticket/17653#comment:3>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.