Skip to content

Add drf-batch to third-party packages documentation - #10092

Open
matink112 wants to merge 1 commit into
encode:mainfrom
matink112:docs/add-drf-batch
Open

matink112 wants to merge 1 commit into
encode:mainfrom
matink112:docs/add-drf-batch

Conversation

@matink112

@matink112 matink112 commented Oct 31, 2026 •

Copy link
Copy Markdown

Description

Adds drf-batch to the documentation:

  • Third party packages → Serializers: one-line entry.
  • API guide → Serializers → Third party packages: a short "DRF Batch" section.
  • API guide → Serializers → Customizing multiple create: a one-sentence note that the bulk_create example only batches the write. Items are still validated one at a time, so related-field lookups and queries in validate() 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=True payload 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_on on 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 APIClient and check every response.

Related to #9607: the many=True validation case (1,000 rows × 3 related fields → ~3,000 queries). It does not address the ManyRelatedField (M2M) case in the original report.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant