Repository navigation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changed line is likely a correct DRF fix, but there is a more serious data-shape issue nearby.
1.
data=keyword changeIf
ChatUserSerializer.BatchDeleteInstanceis a DRFSerializersubclass, this change is correct:In DRF, the first positional argument is
instance, notdata:So the original:
would pass the dict as
instance, not as input data, which is wrong for validation/serialization.Caveat: If
BatchDeleteInstanceis a custom class, confirm its constructor actually acceptsdata=. If its signature is something like__init__(self, payload), the keyword change will break.2. Main issue:
request.datais likely nested incorrectlyThis part is suspicious:
If the client sends:
{"ids": [1, 2, 3]}then
request.datais:{"ids": [1, 2, 3]}and the serializer receives:
{"ids": {"ids": [1, 2, 3]}}So
idsbecomes a dict instead of a list. That is almost certainly a bug.It is also inconsistent with the operation-object lambda above:
which correctly extracts
request.data.get("ids", []).Suggested correction
If
request.datacan also be a raw list, handle that explicitly, but prefer a consistent payload shape:{"ids": [1, 2, 3]}3. Additional potential issues
ids: Ensureids=[]does not accidentally mean “delete all”. Reject empty lists.idsis a list of integers, not a string, dict, or arbitrary objects.batch_delete()loops and deletes one by one, optimize withfilter(pk__in=ids).delete()or a bulk update/soft-delete.idslist for the operation object and the deletion logic.QueryDicthandling: If form-encoded requests are supported,request.data.get("ids")may not return a list. Usegetlist("ids")or require JSON.Verdict
The
data=change is probably correct for DRF. However, the bigger issue is that{"ids": request.data}likely nests the whole request body underids. Userequest.data.get("ids", [])instead, and validate/authorize the IDs before deleting.