Skip to content

feat!: patchTemplateMeta to use optional fields#24984

Merged
Emyrk merged 19 commits into
mainfrom
steven/plat-184-update-updatetemplatemeta-to-have-all-the-fields-optional
May 11, 2026
Merged

feat!: patchTemplateMeta to use optional fields#24984
Emyrk merged 19 commits into
mainfrom
steven/plat-184-update-updatetemplatemeta-to-have-all-the-fields-optional

Conversation

@Emyrk
Copy link
Copy Markdown
Member

@Emyrk Emyrk commented May 5, 2026

Closes #13112

Breaking Change: Removed status code StatusNotModified when no diffs occur in a patch. Now the patch is always applied and a template is always returned.

What this does

  • Converts every settable field on codersdk.UpdateTemplateMeta to a pointer.
  • Removes the check to see if a change has an update
    • The code that was checking every single field if there was a diff feels very error prone. It has to be kept in sync with new fields. It had to handle both template fields and schedule fields. In practice, this does not save us much and can only cause issues.
    • All template meta updates are written to the DB, even in in the no-op case

Most of this diff is unit testing every single field


This pull request was generated by a Coder agent on behalf of @Emyrk.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Docs preview

📖 View docs preview for docs/reference/api/schemas.md

@Emyrk Emyrk changed the title feat(codersdk): make UpdateTemplateMeta fields optional feat: make UpdateTemplateMeta fields optional May 5, 2026
Comment thread cli/templateedit_test.go Outdated
Comment on lines +317 to +324
// Either a successful no-op or a 304 Not Modified is
// acceptable: the request itself is allowed (it does not
// require enterprise entitlement), and AGPL silently
// ignores enterprise-only schedule fields, so the
// effective template state is unchanged.
if err != nil {
require.ErrorContains(t, err, "not modified")
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

304's are considered errors by the cli. I'm not trying to change that behavior here

@@ -0,0 +1,162 @@
package coderd
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has the meat of the change.

Extracted the settings to it's own function for easier unit test

@Emyrk Emyrk marked this pull request as ready for review May 7, 2026 16:30
@Emyrk Emyrk force-pushed the steven/plat-184-update-updatetemplatemeta-to-have-all-the-fields-optional branch from 37fc1d8 to 63db44b Compare May 8, 2026 15:37
@Emyrk
Copy link
Copy Markdown
Member Author

Emyrk commented May 11, 2026

/coder-agents-review

Copy link
Copy Markdown
Contributor

@coder-agents-review coder-agents-review Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First-pass review (Netero only). This is a mechanical scan; the full review panel has not yet reviewed this PR and will review after these findings are addressed.

The conversion to pointer fields is clean and the test matrix is thorough. One test-correctness issue (P2) and several stale-comment leftovers from the 304 removal.

1 P2, 4 P3, 1 Nit.

"The handler now always writes to the DB and returns 200 OK; remove the 304 references." Netero, surveying the battlefield

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/templates_meta_update_internal_test.go Outdated
Comment thread coderd/templates_meta_update_internal_test.go
Comment thread coderd/templates_meta_update.go Outdated
Comment thread coderd/templates_test.go Outdated
Comment thread coderd/templates_test.go Outdated
Comment thread coderd/templates_test.go Outdated
Emyrk added 17 commits May 11, 2026 09:05
UpdateTemplateMeta is the body for PATCH /api/v2/templates/{template}.
Convert all settable fields to pointers so omitted fields preserve the
existing template value instead of overwriting with the Go zero value.

Closes #13112
…lper

Splits the resolution phase of patchTemplateMeta into a pure helper that
takes (template, scheduleOpts, req) and returns a templateMetaUpdate
struct plus parsing-only validation errors. The handler now calls this
helper once and references resolved.foo throughout, which makes the
mapping from request -> persisted state explicit and testable without
spinning up a coderd instance.

Adds an internal table-driven test (one case per pointer field) that
verifies an empty PATCH preserves every value and that each single-field
PATCH changes only that field, plus targeted cases for the one-shot
intent flags (DisableEveryoneGroupAccess, UpdateWorkspaceLastUsedAt,
UpdateWorkspaceDormantAt) and parsing-error paths.

No behavior change.
…fault CORS

The CORS subtests call UpdateTemplateMeta with CORSBehavior set to the
same value the freshly-created template already has. Now that the API
treats unchanged fields as a true no-op, that returns 304 Not Modified
which the SDK surfaces as an error.

Tolerate 'not modified' and fetch the template to keep the assertion
on the response value meaningful.
@Emyrk Emyrk force-pushed the steven/plat-184-update-updatetemplatemeta-to-have-all-the-fields-optional branch from 1f1aa5d to c0a4ab1 Compare May 11, 2026 14:05
Comment thread coderd/templates_meta_update.go Outdated
The previous docstring suggested the resolver performed all user-facing validation. It does not. The resolver only validates shape (parsing weekday strings and CORS enums). Range and content checks (e.g. activityBumpMillis >= 0, failureTTLMillis >= 1 minute) live in the caller.
Comment thread cli/templateedit_test.go
err := inv.WithContext(ctx).Run()

require.ErrorContains(t, err, "not modified")
require.NoError(t, err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone might be impacted by this behavior change, but I think this is a net improvement to the CLI ergonomics (folks don't need to ignore the no-change error).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mark this as a breaking change? Any clients expecting a 304 will be in for a surprise.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it should be called out.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll mark it a breaking change.

A 304 being an error was very annoying to handle. And it was not a sentinel error, so we always did a string comparison

Comment thread coderd/templates_meta_update.go Outdated
Comment thread coderd/templates_meta_update.go Outdated
Comment thread coderd/templates_meta_update.go
Comment thread coderd/templates_test.go Outdated
@Emyrk Emyrk changed the title feat: make UpdateTemplateMeta fields optional feat!: patchTemplateMeta to use optional fields May 11, 2026
@github-actions github-actions Bot added the release/breaking This label is applied to PRs to detect breaking changes as part of the release process label May 11, 2026
@Emyrk Emyrk requested review from jscottmiller and zedkipp May 11, 2026 16:56
@Emyrk Emyrk merged commit 19573e8 into main May 11, 2026
29 checks passed
@Emyrk Emyrk deleted the steven/plat-184-update-updatetemplatemeta-to-have-all-the-fields-optional branch May 11, 2026 17:43
@github-actions github-actions Bot locked and limited conversation to collaborators May 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release/breaking This label is applied to PRs to detect breaking changes as part of the release process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update UpdateTemplateMeta to have all the fields optional

3 participants