[Django] #28821: Allow bulk_create on multi-table inheritance when possible

已查看 106 次
跳至第一个未读帖子

Django

未读,
2017年11月20日 12:36:052017/11/20
收件人 django-...@googlegroups.com
#28821: Allow bulk_create on multi-table inheritance when possible
-------------------------------------+-------------------------------------
Reporter: Joey | Owner: nobody
Wilhelm |
Type: New | Status: new
feature |
Component: Database | Version: master
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 |
-------------------------------------+-------------------------------------
According to
[https://github.com/django/django/blob/a2626cb3fec2e67bb0ec4be2e992e1a836b7567e/django/db/models/query.py#L423
this comment] in `bulk_create`:

{{{#!python
# When you bulk insert you don't get the primary keys back (if
it's an
# autoincrement, except if can_return_ids_from_bulk_insert=True),
so
# you can't insert into the child tables which references this.
}}}

This implies that, if we do retrieve primary keys from the parent model's
bulk insert, then it is possible to bulk insert into the child tables
automatically.

Now that Django does have the ability to automatically retrieve, and set,
primary keys on a bulk create operation, it would be nice to allow this
use case when possible (specifically, when the backend has
`can_return_ids_from_bulk_insert=True`). Keying it off this feature would
give PostgreSQL this ability immediately, and then let it work for Oracle
as soon as retrieval of PKs is fully supported on that engine as well.

Also, regardless if Django does this automatically, I would like to be
able to manually set the `_ptr` fields on the child records in order to
affect a bulk_create without the need for automatic retrieval of IDs.
However, even that is not possible, as the `bulk_create` method
[https://github.com/django/django/blob/a2626cb3fec2e67bb0ec4be2e992e1a836b7567e/django/db/models/query.py#L448
fails on multi-table inheritance in all cases].

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

Django

未读,
2017年11月20日 14:44:522017/11/20
收件人 django-...@googlegroups.com
#28821: Allow QuerySet.bulk_create() on multi-table inheritance when possible
-------------------------------------+-------------------------------------
Reporter: Joey Wilhelm | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

* stage: Unreviewed => Accepted


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

Django

未读,
2017年11月27日 11:48:072017/11/27
收件人 django-...@googlegroups.com
#28821: Allow QuerySet.bulk_create() on multi-table inheritance when possible
-------------------------------------+-------------------------------------
Reporter: Joey Wilhelm | Owner: Abhishek
| Gautam
Type: New feature | Status: assigned

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

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

* status: new => assigned
* cc: Abhishek Gautam (added)
* owner: nobody => Abhishek Gautam


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

Django

未读,
2018年1月14日 10:59:322018/1/14
收件人 django-...@googlegroups.com
#28821: Allow QuerySet.bulk_create() on multi-table inheritance when possible
-------------------------------------+-------------------------------------
Reporter: Joey Wilhelm | Owner: (none)

Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

* status: assigned => new
* owner: Abhishek Gautam => (none)


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

Django

未读,
2019年11月29日 04:21:072019/11/29
收件人 django-...@googlegroups.com
#28821: Allow QuerySet.bulk_create() on multi-table inheritance when possible
-------------------------------------+-------------------------------------

Reporter: Joey Wilhelm | Owner: (none)
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

* cc: Sardorbek Imomaliev (added)


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

Django

未读,
2020年11月2日 13:55:572020/11/2
收件人 django-...@googlegroups.com
#28821: Allow QuerySet.bulk_create() on multi-table inheritance when possible
-------------------------------------+-------------------------------------

Reporter: Joey Wilhelm | Owner: (none)
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

Comment (by Daniel Alley):

This would be an excellent feature and we would really love to be able to
use it.

I would like to be able to manually set the _ptr fields on the child
records in order to affect a bulk_create without the need for automatic
retrieval of IDs.

In certain circumstances (think UUID PKs) it might also be possible, at
least with Postgresql (don't know about the others), to do it the other
way around. Foreign key integrity checks are deferred to the end of the
transaction, so you could save all of the child tables first, and then
save all the parent tables. As long as the entire operation is wrapped in
a single transaction, it wouldn't matter that `_ptr` temporarily held an
invalid FK.

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

Django

未读,
2020年12月10日 19:46:372020/12/10
收件人 django-...@googlegroups.com
#28821: Allow QuerySet.bulk_create() on multi-table inheritance when possible
-------------------------------------+-------------------------------------

Reporter: Joey Wilhelm | Owner: (none)
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
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 Jon Dufresne):

* cc: jon.dufresne@… (added)
* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/13763

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

Django

未读,
2020年12月11日 03:39:142020/12/11
收件人 django-...@googlegroups.com
#28821: Allow QuerySet.bulk_create() on multi-table inheritance when possible
-------------------------------------+-------------------------------------
Reporter: Joey Wilhelm | Owner: Jon
| Dufresne

Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
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 Mariusz Felisiak):

* owner: (none) => Jon Dufresne


* status: new => assigned


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

Django

未读,
2020年12月18日 03:18:072020/12/18
收件人 django-...@googlegroups.com
#28821: Allow QuerySet.bulk_create() on multi-table inheritance when possible
-------------------------------------+-------------------------------------

Reporter: Joey Wilhelm | Owner: Jon
| Dufresne
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
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/28821#comment:8>

Django

未读,
2021年10月19日 08:06:422021/10/19
收件人 django-...@googlegroups.com
#28821: Allow QuerySet.bulk_create() on multi-table inheritance when possible
-------------------------------------+-------------------------------------

Reporter: Joey Wilhelm | Owner: Jon
| Dufresne
Type: New feature | Status: assigned
Component: Database layer | Version: dev

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

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Shai Berger):

* cc: Shai Berger (added)


Comment:

There's a naive implementation of a special case in the new broken-down-
models library. Could be interesting to compare.
https://github.com/Matific/broken-down-
models/blob/main/bdmodels/models.py#L114 (actual line number may have
changed by the time you read this, of course)

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

Django

未读,
2021年10月23日 06:12:562021/10/23
收件人 django-...@googlegroups.com
#28821: Allow QuerySet.bulk_create() on multi-table inheritance when possible
-------------------------------------+-------------------------------------

Reporter: Joey Wilhelm | Owner: Jon
| Dufresne
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam Johnson):

* cc: Adam Johnson (added)


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

Django

未读,
2022年7月22日 04:34:272022/7/22
收件人 django-...@googlegroups.com
#28821: Allow QuerySet.bulk_create() on multi-table inheritance when possible
-------------------------------------+-------------------------------------

Reporter: Joey Wilhelm | Owner: (none)
Type: New feature | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* owner: Jon Dufresne => (none)


* status: assigned => new


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

Django

未读,
2023年12月25日 15:38:142023/12/25
收件人 django-...@googlegroups.com
#28821: Allow QuerySet.bulk_create() on multi-table inheritance when possible
-------------------------------------+-------------------------------------
Reporter: Joey Wilhelm | Owner: HAMA
| Barhamou

Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

* owner: (none) => HAMA Barhamou
* needs_better_patch: 1 => 0
* has_patch: 1 => 0


* status: new => assigned


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

Django

未读,
2024年1月18日 13:23:331月18日
收件人 django-...@googlegroups.com
#28821: Allow QuerySet.bulk_create() on multi-table inheritance when possible
-------------------------------------+-------------------------------------

Reporter: Joey Wilhelm | Owner: HAMA
| Barhamou
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

Comment (by HAMA Barhamou):

Hi Django Team,

I am picking up where @jdufresne left off . My recent commits
([https://github.com/django/django/pull/17754]) introduce the initial
steps towards enabling QuerySet.bulk_create to support multi-table
inheritance.

This is just the beginning, and I plan to make iterative improvements to
this feature. Looking forward to your feedback and suggestions as we
progress.

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

Django

未读,
2024年1月18日 13:33:251月18日
收件人 django-...@googlegroups.com
#28821: Allow QuerySet.bulk_create() on multi-table inheritance when possible
-------------------------------------+-------------------------------------

Reporter: Joey Wilhelm | Owner: HAMA
| Barhamou
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
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 HAMA Barhamou):

* has_patch: 0 => 1


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

Django

未读,
2024年1月18日 23:40:461月18日
收件人 django-...@googlegroups.com
#28821: Allow QuerySet.bulk_create() on multi-table inheritance when possible
-------------------------------------+-------------------------------------

Reporter: Joey Wilhelm | Owner: HAMA
| Barhamou
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
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


Comment:

Marking as "needs improvement" as author mentioned that it's a draft.

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

回复全部
回复作者
转发
0 个新帖子