[Fixes #14473] Fix payload handling in the users transfer_resources endpoint - #14474
Open
christianbraun wants to merge 1 commit into
Open
[Fixes #14473] Fix payload handling in the users transfer_resources endpoint#14474christianbraun wants to merge 1 commit into
christianbraun wants to merge 1 commit into
Conversation
`POST /api/v2/users/{pk}/transfer_resources` could not be called with the
minimal documented payload, and one of its guards was unreachable:
- `if not target_user and previous_owner` only rejected a missing `newOwner`
when `currentOwner` was present. Without either, the request fell through to
`get_object_or_404(User, id=None)` and answered 404 instead of 400.
- `currentOwner` is optional (`filter_payload = dict(owner=previous_owner or
user)`), but the loop resolved it unconditionally with `get_object_or_404`,
so `{"newOwner": <id>}` on its own always returned 404. It is now resolved
once, up front, defaulting to the user the resources are read from.
- With a JSON body and no `resources` key the subset is `None`, so
`len(transfer_resource_subset)` raised TypeError when the source user is not
a superuser. Skipping the subset check when there is no subset keeps the
whole-account transfer working.
`test_transfer_resources_nopayload` asserted the 404 from the first bug and now
asserts 400. Added `test_transfer_resources_without_current_owner`, which sends
a JSON body and covers the other two.
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @christianbraun on file. In order for us to review and merge your code, please contact the project maintainers to get yourself added. |
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
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.
Fixes #14473.
POST /api/v2/users/{pk}/transfer_resourcescould not be called with the minimal payload, and one of its guards was unreachable.if not target_user and previous_owneronly rejected a missingnewOwnerwhencurrentOwnerwas present. Without either, the request fell through toget_object_or_404(User, id=None)and answered 404 instead of 400.currentOwneris optional as far as the filter is concerned (filter_payload = dict(owner=previous_owner or user)), but the loop resolved it unconditionally withget_object_or_404, so{"newOwner": <id>}on its own always returned 404. It is now resolved once, up front, defaulting to the user the resources are read from - which also takes the query out of the loop.resourceskey the subset isNone, solen(transfer_resource_subset)raisedTypeErrorwhenever the source user is not a superuser. Skipping the subset check when there is no subset keeps the whole-account transfer working.Everything that already worked keeps its status code. The one behaviour change is the empty-body case, which now answers the 400 the guard was clearly written for:
test_transfer_resources_nopayloadasserted the 404 from the first bug and now asserts 400.test_transfer_resources_without_current_owneris new and covers the other two - it sends a JSON body, soresourcesis genuinely absent rather than the empty list a form-encodedQueryDict.getlistreturns. That difference is why the existing tests pass today.I have not been able to run the full Django suite locally;
blackandflake8are clean on both files.