[Django] #31685: Add `update_or_create()` in bulk

30 views
Skip to first unread message

Django

unread,
Jun 10, 2020, 4:58:36 PM6/10/20
to django-...@googlegroups.com
#31685: Add `update_or_create()` in bulk
-------------------------------------+-------------------------------------
Reporter: Vitor | Owner: nobody
Sousa Pereira |
Type: New | Status: new
feature |
Component: Database | Version: master
layer (models, ORM) | Keywords: bulk insert update
Severity: Normal | upsert
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
It would be useful having a parameter in `bulk_create()`, like
`bulk_create(objs, upsert=True)` or `bulk_create(objs,
update_conflicts=True)`, that lets you update existing rows when there's a
conflict, much like what you can already do for a single entity with
`update_or_create()`.

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

Django

unread,
Jun 11, 2020, 1:07:28 AM6/11/20
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 0 | Needs documentation: 0

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

* cc: Tom Forbes (added)
* stage: Unreviewed => Accepted


Comment:

Agreed, it would be great to support updating conflicts with
`bulk_create()`:

- [https://www.postgresql.org/docs/current/sql-insert.html#SQL-ON-CONFLICT
ON CONFLICT DO UPDATE] on PostgreSQL and SQLite,
- [https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html ON
DUPLICATE KEY UPDATE] on MySQL.

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

Django

unread,
Jun 11, 2020, 12:20:29 PM6/11/20
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chih Sean Hsu):

* cc: Chih Sean Hsu (added)
* owner: nobody => Chih Sean Hsu
* status: new => assigned


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

Django

unread,
Jun 14, 2020, 1:38:58 PM6/14/20
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 0 | Needs documentation: 0

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

Comment (by Chih Sean Hsu):

I have opened PR https://github.com/django/django/pull/13065. It is still
on going.

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

Django

unread,
Jun 30, 2020, 9:26:29 AM6/30/20
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chih Sean Hsu):

* needs_docs: 0 => 1
* has_patch: 0 => 1
* needs_tests: 0 => 1


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

Django

unread,
Nov 1, 2020, 9:07:43 AM11/1/20
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chih Sean Hsu):

* needs_docs: 1 => 0
* needs_tests: 1 => 0


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

Django

unread,
Nov 5, 2020, 10:01:37 AM11/5/20
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 1 | Needs documentation: 0

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

Comment (by Chih Sean Hsu):

It's done and waiting for review.

--
Ticket URL: <https://code.djangoproject.com/ticket/31685#comment:6>

Django

unread,
Nov 9, 2020, 6:04:39 AM11/9/20
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 1 | Needs documentation: 0

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

Comment (by Alexandr Tatarinov):

Added a comment to pull request about potential room for improvement.

--
Ticket URL: <https://code.djangoproject.com/ticket/31685#comment:7>

Django

unread,
Mar 3, 2021, 9:36:50 AM3/3/21
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 1 | Needs documentation: 0

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

* cc: Adam Johnson (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/31685#comment:8>

Django

unread,
Jul 13, 2021, 2:05:19 AM7/13/21
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: dev

(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31685#comment:9>

Django

unread,
Oct 18, 2021, 10:34:18 AM10/18/21
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chih Sean Hsu):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31685#comment:10>

Django

unread,
Oct 22, 2021, 5:08:49 AM10/22/21
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1

* needs_docs: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31685#comment:11>

Django

unread,
Oct 22, 2021, 10:50:57 AM10/22/21
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chih Sean Hsu):

* needs_better_patch: 1 => 0

* needs_docs: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31685#comment:12>

Django

unread,
Oct 25, 2021, 7:04:31 AM10/25/21
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31685#comment:13>

Django

unread,
Nov 4, 2021, 6:08:17 AM11/4/21
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chih Sean Hsu):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31685#comment:14>

Django

unread,
Nov 16, 2021, 1:16:54 AM11/16/21
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chih Sean Hsu):

* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31685#comment:15>

Django

unread,
Nov 18, 2021, 1:34:44 AM11/18/21
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31685#comment:16>

Django

unread,
Jan 17, 2022, 10:27:30 AMJan 17
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Accepted
upsert |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chih Sean Hsu):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31685#comment:17>

Django

unread,
Jan 19, 2022, 5:04:55 AMJan 19
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: bulk insert update | Triage Stage: Ready for
upsert | checkin
Has patch: 1 | Needs documentation: 0

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

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/31685#comment:18>

Django

unread,
Jan 19, 2022, 11:52:33 PMJan 19
to django-...@googlegroups.com
#31685: Support updating conflicts with QuerySet.bulk_create().
-------------------------------------+-------------------------------------
Reporter: Vitor Pereira | Owner: Chih Sean
| Hsu
Type: New feature | Status: closed

Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: bulk insert update | Triage Stage: Ready for
upsert | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"0f6946495a8ec955b471ca1baaf408ceb53d4796" 0f694649]:
{{{
#!CommitTicketReference repository=""
revision="0f6946495a8ec955b471ca1baaf408ceb53d4796"
Fixed #31685 -- Added support for updating conflicts to
QuerySet.bulk_create().

Thanks Florian Apolloner, Chris Jerdonek, Hannes Ljungberg, Nick Pope,
and Mariusz Felisiak for reviews.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31685#comment:19>

Reply all
Reply to author
Forward
0 new messages