[Django] #29126: Model.update_or_create method pk issue.

6 views
Skip to first unread message

Django

unread,
Feb 12, 2018, 5:53:25 AM2/12/18
to django-...@googlegroups.com
#29126: Model.update_or_create method pk issue.
-------------------------------------+-------------------------------------
Reporter: Théo | Owner: nobody
"Bob" Massard |
Type: Bug | Status: new
Component: Database | Version: 2.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Upon using the `update_or_create` method on a Model which has a modified
`pk` field, an IntegrityError happens.

`psycopg2.IntegrityError: duplicate key value violates unique constraint
"tags_pkey"`

The PrimaryKey is an IntegerField with a modified `db_column`.

--
Ticket URL: <https://code.djangoproject.com/ticket/29126>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 13, 2018, 10:00:48 AM2/13/18
to django-...@googlegroups.com
#29126: Model.update_or_create method pk issue.
-------------------------------------+-------------------------------------
Reporter: Théo "Bob" Massard | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Can you please include the model and steps to reproduce?

--
Ticket URL: <https://code.djangoproject.com/ticket/29126#comment:1>

Django

unread,
Feb 14, 2018, 10:07:21 AM2/14/18
to django-...@googlegroups.com
#29126: Document the behavior of QuerySet.update_or_create() with manually
specified pks
--------------------------------------+------------------------------------

Reporter: Théo "Bob" Massard | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* type: Bug => Cleanup/optimization
* has_patch: 0 => 1
* component: Database layer (models, ORM) => Documentation
* stage: Unreviewed => Accepted


Comment:

If I understand the situation you're describing, I believe this is
expected behavior (see #8419). [https://github.com/django/django/pull/9698
PR] to document and test it.

--
Ticket URL: <https://code.djangoproject.com/ticket/29126#comment:2>

Django

unread,
Feb 15, 2018, 3:51:29 AM2/15/18
to django-...@googlegroups.com
#29126: Document the behavior of QuerySet.update_or_create() with manually
specified pks
--------------------------------------+------------------------------------
Reporter: Théo "Bob" Massard | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 2.0
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Théo "Bob" Massard):

* status: new => closed
* resolution: => fixed


Comment:

Oh, thanks a lot for pointing it out and updating the documentation!

--
Ticket URL: <https://code.djangoproject.com/ticket/29126#comment:3>

Django

unread,
Feb 15, 2018, 1:37:48 PM2/15/18
to django-...@googlegroups.com
#29126: Document the behavior of QuerySet.update_or_create() with manually
specified pks
--------------------------------------+------------------------------------
Reporter: Théo "Bob" Massard | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 2.0
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"e917ea6bec45d7f789ca96a13be15df9521963e1" e917ea6b]:
{{{
#!CommitTicketReference repository=""
revision="e917ea6bec45d7f789ca96a13be15df9521963e1"
Fixed #29126 -- Doc'd the behavior of QuerySet.update_or_create() with
manually specified pks.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29126#comment:4>

Django

unread,
Feb 15, 2018, 1:57:43 PM2/15/18
to django-...@googlegroups.com
#29126: Document the behavior of QuerySet.update_or_create() with manually
specified pks
--------------------------------------+------------------------------------
Reporter: Théo "Bob" Massard | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 2.0
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"4b8e433e1cacd7405d6ae0a88d1776adc0068f10" 4b8e433]:
{{{
#!CommitTicketReference repository=""
revision="4b8e433e1cacd7405d6ae0a88d1776adc0068f10"
[2.0.x] Fixed #29126 -- Doc'd the behavior of QuerySet.update_or_create()
with manually specified pks.

Backport of e917ea6bec45d7f789ca96a13be15df9521963e1 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29126#comment:5>

Reply all
Reply to author
Forward
0 new messages