Skip to content

fix: exclude read-only fields from service update requests - #96

Open
juztim wants to merge 2 commits into
SierraJC:mainfrom
juztim:fix/service-update-readonly-fields
Open

juztim wants to merge 2 commits into
SierraJC:mainfrom
juztim:fix/service-update-readonly-fields

Conversation

@juztim

@juztim juztim commented Jan 13, 2026

Copy link
Copy Markdown

Summary

Fixes 422 Unprocessable Content errors when updating coolify_service resources.

Problem

The Coolify API rejects PATCH requests to /services/{uuid} that include read-only fields:

  • server_uuid
  • project_uuid
  • environment_name
  • environment_uuid
  • destination_uuid

The auto-generated UpdateServiceByUuidJSONRequestBody includes these fields as required (not omitempty), causing every update to fail with:

Received 422 Unprocessable Content updating service: uuid=xxx. Details: 
{"message":"Validation failed.","errors":{
  "destination_uuid":["This field is not allowed."],
  "environment_name":["This field is not allowed."],
  ...
}}

Solution

  • Create a custom ServiceUpdateRequest struct with only mutable fields (name, description, docker_compose_raw, instant_deploy)
  • Use UpdateServiceByUuidWithBody to send a custom JSON payload instead of the generated type

Testing

Tested against Coolify v4.x API - updates now succeed without 422 errors.

The Coolify API rejects PATCH requests to services that include read-only
fields (server_uuid, project_uuid, environment_name, environment_uuid,
destination_uuid). The auto-generated API types include these fields as
required, but they should not be sent on updates.

This creates a custom ServiceUpdateRequest struct with only the mutable
fields and uses UpdateServiceByUuidWithBody to send a custom JSON payload.

Fixes 422 Unprocessable Content errors when updating services.
@SierraJC

Copy link
Copy Markdown
Owner

Thanks for the fix @juztim , looks good!

I try to keep upstream API related fixes in the tools/overlay.yml file (this modifies the api spec), which is the source of the auto-generated UpdateServiceByUuidJSONRequestBody object. So you could define the "correct" update body in there for consistency, while waiting for the upstream to be fixed. What do you think?

@juztim

juztim commented Jan 17, 2026

Copy link
Copy Markdown
Author

I moved the service update fix into tools/overlay.yml so the generated UpdateServiceByUuid request body no longer includes the read-only fields, and docker_compose_raw stays required. Regenerated the OpenAPI client + provider code, then switched the service update call back to UpdateServiceByUuidWithResponse using the generated type. Commit: 8c245e3.

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.

2 participants