#19544: IntegrityError during Many To Many add()
-------------------------------------+-------------------------------------
     Reporter:  Kronuz               |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |                  Version:  1.4
    Component:  Database layer       |               Resolution:
  (models, ORM)                      |             Triage Stage:
     Severity:  Normal               |  Someday/Maybe
     Keywords:                       |      Needs documentation:  0
    Has patch:  0                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by Patrick Robertson <django@…>):

 Just my 2¢ - I just got this error on my production server, which is
 pretty nasty.

 I'm using postgres

 Any temporary solutions would be appreciated, as for me at least this is
 quite a serious bug


 Traceback:
 This is just from a simple `form.save()` call, and I haven't experienced
 it once in my testing.
 I'd argue that this should be marked with a higher priority, regardless of
 how easy it is to implement... :)

 {{{
  File "/somewhere/webapps/ordersystem/ordersystem/ordersystem/views.py",
 line 1188, in form_valid
    customer = form.save()

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/forms/models.py", line 446, in save
    construct=False)

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/forms/models.py", line 100, in save_instance
    save_m2m()

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/forms/models.py", line 96, in save_m2m
    f.save_form_data(instance, cleaned_data[f.name])

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/db/models/fields/related.py", line 1529, in save_form_data
    setattr(instance, self.attname, data)

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/utils/functional.py", line 242, in __setattr__
    setattr(self._wrapped, name, value)

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/db/models/fields/related.py", line 842, in __set__
    manager.add(*value)

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/db/models/fields/related.py", line 583, in add
    self._add_items(self.source_field_name, self.target_field_name, *objs)

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/db/models/fields/related.py", line 672, in _add_items
    for obj_id in new_ids

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/db/models/query.py", line 359, in bulk_create
    self._batched_insert(objs_without_pk, fields, batch_size)

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/db/models/query.py", line 838, in _batched_insert
    using=self.db)

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/db/models/manager.py", line 232, in _insert
    return insert_query(self.model, objs, fields, **kwargs)

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/db/models/query.py", line 1514, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/db/models/sql/compiler.py", line 903, in execute_sql
    cursor.execute(sql, params)

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/db/utils.py", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)

  File "/somewhere/.virtualenvs/ordersystem/lib/python2.7/site-
 packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)

 IntegrityError: duplicate key value violates unique constraint
 "ordersystem_customer_disliked_vege_customer_id_vegetable_id_key"
 DETAIL:  Key (customer_id, vegetable_id)=(67, 37) already exists.
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19544#comment:5>
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/064.26250a33a693554f9a163648d59774e9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to