Fixed #28821 -- Supported multi-table inheritance in bulk_create().#17754
Open
HamaBarhamou wants to merge 6 commits intodjango:mainfrom
Open
Fixed #28821 -- Supported multi-table inheritance in bulk_create().#17754HamaBarhamou wants to merge 6 commits intodjango:mainfrom
HamaBarhamou wants to merge 6 commits intodjango:mainfrom
Conversation
d837301 to
f4742f7
Compare
Member
|
Hi 👋 @HamaBarhamou. Just strolling by to make sure you know to unset "Patch needs improvement" on the linked ticket when tests are passing and you're ready for a review. Cheers! |
Author
@jacobtylerwalls Thanks for the reminder. I'll do it once I'm ready for the revision. |
…- Django Ticket: #28821 This commit introduces the initial implementation for Django ticket #28821, aiming to enable QuerySet.bulk_create to handle models with multi-table inheritance. Added the _bulk_create_multi_table method to manage parent and child models during bulk insertions, taking into account the database backend's ability to return IDs after bulk operations. Note: This is an early-stage implementation and further testing and development are required to ensure functionality and robustness.
…t.bulk_create(). This introduces support for bulk_create() on multi-table inheritance (MTI) child models in two situations: * Backends that can return rows from bulk inserts (e.g. PostgreSQL and SQLite ≥ 3.35): the top-most parent rows are inserted first and their primary keys are propagated through any intermediate MTI levels before inserting the child rows. * Backends without RETURNING: a single MTI level is supported when each child instance has its parent pointer pre-set (i.e., child.pk equals parent.pk). In practice, bulk-create parents first, then bulk-create children with id=parent.pk. Conflict handling (ignore_conflicts/update_conflicts) is intentionally not supported for MTI in this initial version and now raises django.db.utils.NotSupportedError. The MTI path is factored into an internal _bulk_create_multi_table() helper; the non-MTI behavior (including conflict options) remains unchanged. Object state is updated so that instances returned from bulk_create() have _state.adding = False and _state.db set appropriately. Tests: * Single-level and multi-level MTI with RETURNING. * Preset-parent-pointer fast path (including UUID PKs). * Mixed preset/non-preset on RETURNING backends. * Respect for batch_size on the MTI path. * Explicit parent link attname handling. * Instance state after insert. * Negative cases: non-RETURNING without preset pointer; conflict options on MTI. Docs: * Expand bulk_create() docs with a “Multi-table inheritance” subsection, list supported scenarios and limitations, and clarify behavior. * Add a note in the 6.1 release notes. Remove obsolete test asserting that MTI is universally unsupported.
…upport proxy MTI leaves with preset parent pointer. Detect multi-table inheritance against the concrete model instead of the (possibly proxy) model so proxies don't bypass the MTI path. In the MTI code path, resolve self.model to its concrete_model to avoid inserting parent-only columns into the leaf table. Also ensure instance state (_state.adding/db) is updated on the preset-parent fast path. Add tests: - bulk_create on a proxy over an MTI leaf with preset parent pointer - bulk_create on a double-proxy over an MTI leaf with preset parent pointer Verified locally on SQLite, PostgreSQL, and MariaDB.
…double-proxy). Use parent_link attname and create() parents so PKs are known on non-RETURNING backends.
51b48a9 to
0046141
Compare
Author
|
ready for revision |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi Django Team,
I am picking up where @jdufresne [PR] left off on ticket #28821. My recent commits introduce the initial steps towards enabling
QuerySet.bulk_createto 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.
Best,
HAMA Barhamou