#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:  1                    |  Patch needs improvement:  1
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
Changes (by akaariai):

 * needs_better_patch:  0 => 1


Comment:

 The get_db_prep_value seems like the right place, because that is called
 in all the right places. The only other option I can see is to create a
 new method for this.

 The get_db_prep_value is already doing some validation, it calls
 get_prep_value which calls int(value), and that can raise a `ValueError`.

 There is a small mistake in the error message. It says zero is not
 accepted for primary key. This isn't true for `MySQL`.
 {{{
 mysql> create table testtbl(id integer primary key);
 Query OK, 0 rows affected (0.05 sec)

 mysql> insert into testtbl values(0);
 Query OK, 1 row affected (0.01 sec)

 mysql> select * from testtbl;
 +----+
 | id |
 +----+
 |  0 |
 +----+
 1 row in set (0.00 sec)
 }}}

 I know this is a minor nitpick. But it is also easy to correct. It should
 say that zero is not allowed for `AutoFields`.

 There should be a test for bulk_create, too. Maybe, as this ticket is
 about get_or_create add one for that too, although that might be a bit
 redundant.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/17653#comment:12>
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 django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to