Repository navigation
Fix 500 error when PATCHing a Job's compute_resource - #298
Merged
Merged
Conversation
JobSerializerResponse.update() (used by PATCH /job/{id}/) passed the
nested {"id": ...} dict that DRF builds for the compute_resource field
(source="compute_resource.id") straight into setattr(), which Django
rejects for a ForeignKey. Unwrap it to a ComputeResource instance (or
None) first, mirroring the same fix already applied to
JobSerializerRequest.create(). An unknown compute_resource id now
raises a 400 validation error instead of an unhandled 500.
Adds a regression test covering repoint, clear-to-null, and invalid-id
cases.
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.
Summary
PATCH /job/{id}/with acompute_resourcefield always returned an unhandled 500 (ValueError: Cannot assign "{'id': ...}": "Job.compute_resource" must be a "ComputeResource" instance.)compute_resourcefield is declared withsource="compute_resource.id", so DRF buildsvalidated_data["compute_resource"] = {"id": "<value>"}(a nested dict) rather than a flat id.JobSerializerRequest.create()already unwraps this (see the existingCHANGELOG.mdentry for that fix), butJobSerializerResponse.update()- which is whatJobView.patch()actually uses - passed the dict straight through_update_attrs()'ssetattr(), which Django rejects for a ForeignKey.ComputeResourceinstance (orNone, to support clearing the field) before_update_attrs()runs. An unknowncompute_resourceid now raises a clean 400 validation error instead of a 500.Test plan
JobViewTest.test_patch_compute_resourcecovering: repointing a job'scompute_resource, clearing it tonull, and an unknown id producing a 400 (not a 500)laxy_backendtest suite passes locally (104 tests, 9 skipped, 0 failed) against a Postgres 15 test database