Opened 22 months ago

Last modified 20 months ago

#28821 new New feature

Allow QuerySet.bulk_create() on multi-table inheritance when possible

Reported by: Joey Wilhelm Owned by:
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Abhishek Gautam Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


According to this comment in bulk_create:

        # 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 fails on multi-table inheritance in all cases.

Change History (3)

comment:1 Changed 22 months ago by Tim Graham

Summary: Allow bulk_create on multi-table inheritance when possibleAllow QuerySet.bulk_create() on multi-table inheritance when possible
Triage Stage: UnreviewedAccepted

comment:2 Changed 22 months ago by Abhishek Gautam

Cc: Abhishek Gautam added
Owner: changed from nobody to Abhishek Gautam
Status: newassigned

comment:3 Changed 20 months ago by Abhishek Gautam

Owner: Abhishek Gautam deleted
Status: assignednew
Note: See TracTickets for help on using tickets.
Back to Top