Skip to content

Fix 500 error when PATCHing a Job's compute_resource - #298

Merged
pansapiens merged 1 commit into
developfrom
fix/patch-job-compute-resource
Sep 16, 2026
Merged

pansapiens merged 1 commit into
developfrom
fix/patch-job-compute-resource

Conversation

@pansapiens

Copy link
Copy Markdown
Collaborator

Summary

  • PATCH /job/{id}/ with a compute_resource field always returned an unhandled 500 (ValueError: Cannot assign "{'id': ...}"​: "Job.compute_resource" must be a "ComputeResource" instance.)
  • Root cause: the compute_resource field is declared with source="compute_resource.id", so DRF builds validated_data["compute_resource"] = {"id": "<value>"} (a nested dict) rather than a flat id. JobSerializerRequest.create() already unwraps this (see the existing CHANGELOG.md entry for that fix), but JobSerializerResponse.update() - which is what JobView.patch() actually uses - passed the dict straight through _update_attrs()'s setattr(), which Django rejects for a ForeignKey.
  • Fix: unwrap the nested dict to a ComputeResource instance (or None, to support clearing the field) before _update_attrs() runs. An unknown compute_resource id now raises a clean 400 validation error instead of a 500.

Test plan

  • Added JobViewTest.test_patch_compute_resource covering: repointing a job's compute_resource, clearing it to null, and an unknown id producing a 400 (not a 500)
  • Confirmed the new test fails with the exact production error before the fix, and passes after
  • Full laxy_backend test suite passes locally (104 tests, 9 skipped, 0 failed) against a Postgres 15 test database

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.
@pansapiens
pansapiens merged commit 133a8c6 into develop Sep 16, 2026
4 of 5 checks passed
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.

1 participant