Repository navigation
Conversation
List drf-batch under Serializers in the third-party packages page and add a "DRF Batch" entry to the serializers API guide. Also note in "Customizing multiple create" that a bulk_create in ListSerializer.create() only batches the write: items are still validated one at a time, so related-field lookups run once per item.
This branch has not been deployed
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.
Description
Adds drf-batch to the documentation:
bulk_createexample only batches the write. Items are still validated one at a time, so related-field lookups and queries invalidate()run once per item. The note points to drf-batch, the same way the nested-writes section points to DRF Writable Nested.drf-batch collects the lookups for a whole
many=Truepayload before validation, validates every item in memory, and commits the list in a single transaction.Lookups are not limited to the ORM. A field can fetch from an external service (an HTTP API, a cache) once per batch, and fetches can declare
depends_onon each other, e.g. a credit-limit call that needs the customer rows first. Independent fetches run concurrently.The package is on PyPI, with documentation and CI. A separate cookbook has 19 runnable scenarios that send real batches through DRF's
APIClientand check every response.Related to #9607: the
many=Truevalidation case (1,000 rows × 3 related fields → ~3,000 queries). It does not address theManyRelatedField(M2M) case in the original report.