Skip to content

Fix N+1 query in PayloadIOVBulkCreationAPIView - #97

Open
VincenzoImp wants to merge 1 commit into
BNLNPPS:mainfrom
VincenzoImp:fix/bulk-piov-n-plus-one
Open

Fix N+1 query in PayloadIOVBulkCreationAPIView#97
VincenzoImp wants to merge 1 commit into
BNLNPPS:mainfrom
VincenzoImp:fix/bulk-piov-n-plus-one

Conversation

@VincenzoImp

@VincenzoImp VincenzoImp commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #66.

Recreates #67, which was auto-closed when the master branch was deleted during the migration to main. The change is rebased onto current main, where the bulk-create endpoint still issues one PayloadList.objects.get() per input row.

This resolves all referenced PayloadLists in a single filter(name__in=...) query and reports missing ones with a 400 response listing their names, instead of an unhandled DoesNotExist (HTTP 500) on the first missing entry.

Django CI passes on this branch.

PayloadList.objects.get() was called inside the list comprehension,
executing one query per item in the batch. Pre-fetch all needed
PayloadList objects in a single query using filter(name__in=...).

Also adds explicit validation for missing PayloadList names, returning
400 instead of letting DoesNotExist bubble up as 500.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

N+1 query in PayloadIOVBulkCreationAPIView

1 participant