Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#29126 closed Cleanup/optimization (fixed)

Document the behavior of QuerySet.update_or_create() with manually specified pks

Reported by: Théo "Bob" Massard Owned by: nobody
Component: Documentation Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (5)

comment:1 by Tim Graham, 7 years ago

Can you please include the model and steps to reproduce?

comment:2 by Tim Graham, 7 years ago

Component: Database layer (models, ORM)Documentation
Has patch: set
Summary: Model.update_or_create method pk issue.Document the behavior of QuerySet.update_or_create() with manually specified pks
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

If I understand the situation you're describing, I believe this is expected behavior (see #8419). PR to document and test it.

comment:3 by Théo "Bob" Massard, 7 years ago

Resolution: fixed
Status: newclosed

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

comment:4 by Tim Graham <timograham@…>, 7 years ago

In e917ea6b:

Fixed #29126 -- Doc'd the behavior of QuerySet.update_or_create() with manually specified pks.

comment:5 by Tim Graham <timograham@…>, 7 years ago

In 4b8e433:

[2.0.x] Fixed #29126 -- Doc'd the behavior of QuerySet.update_or_create() with manually specified pks.

Backport of e917ea6bec45d7f789ca96a13be15df9521963e1 from master

Note: See TracTickets for help on using tickets.
Back to Top