fix(api): validate channel disableAutoUpdate and accept metadata alias - #3275
Conversation
The public channel endpoint copied disableAutoUpdate straight into the channels insert with no validation. The word "metadata", which the CLI and docs use, is not a member of the disable_update enum, so Postgres rejected it and the raw error escaped as a 500. Validate disableAutoUpdate against the five enum values, map the metadata alias to version_number to match the CLI, and throw a simpleError so bad input returns a 400 with a readable message. This mirrors the updatePackage check next to it. Generated-By: PostHog Desktop Task-Id: ecd3237a-d82e-40c3-9222-64cfd641251a
Merging this PR will improve performance by 98.74%
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
|
|
@coderabbitai full review |
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (2)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughThe channel POST handler now validates ChangesDisable auto-update validation
Priority: ⬇️ Low — Defer this narrow channel POST validation change because it only normalizes supported update strategies and rejects invalid values with a client error. Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to Channel updates now consistently normalize supported disable-auto-update values and return a 400 error for invalid values without modifying the channel. No current merge-blocking risk remains. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Comment |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
MarkZ1966github
left a comment
There was a problem hiding this comment.
Unique note, not in the bot reviews:
The metadata alias is compared with strict equality after a cast, then rewritten to version_number before the allow-list check. Two consequences:
-
The error string lists
metadataas an accepted value, but that string never survives intoincludes(). A client that sendsMetadataorMETADATAgetsinvalid_disable_auto_updateeven though the message told themmetadatais valid. The CLI flag is documented asmetadatain lowercase, so this only bites if another API client capitalizes it. Worth normalizing with.toLowerCase()before the alias map, or droppingmetadatafrom the error text since it is not actually a stored enum member. -
body.disableAutoUpdateis mutated in place. Anything that logs the original request after this block will showversion_numberand hide that the caller sentmetadata. A locallet strategy = ...keeps the inbound payload intact for logs.
The tests cover the happy alias and a typo (meta). A case-fold case would lock the first point down.
Otherwise the mapping matches the CLI, and rejecting unknown strategies with simpleError is the right 400 instead of a raw Postgrest 500.



Summary
Why: An API user set a channel strategy to
metadata— the exact word our CLI and docs use — and got a 500 with no message instead of a saved channel. Their channel silently stayed unconfigured, and each hit minted a new error tracking issue.disableAutoUpdatestraight into the channels insert with no validation and no alias.metadatais not a member of the Postgresdisable_updateenum (major,minor,patch,version_number,none), so the insert threw and the rawPostgrestErrorescaped as a 500.metadata→version_numberbefore it calls us; the public API did not. The siblingupdatePackagefield was validated a few lines above, so this one field was the odd one out.Changes — in
supabase/functions/_backend/public/channel/post.ts:metadataalias toversion_number, matching the CLI.disableAutoUpdateagainst the five enum values and throw asimpleError, so bad input now returns a 400 with a readable message (invalid_disable_auto_update) instead of a 500.Checked the sibling
public/bundle/set_channel.ts: it only acceptsapp_id/version_id/channel_idand never touchesdisableAutoUpdate, so it has no equivalent gap.Test plan
bunx vitest run tests/channel-post.unit.test.ts— added two cases:metadatamaps onto theversion_numberstrategy.invalid_disable_auto_updateerror.bun run typecheck:backendandbun run lint:ox:backendpass.Screenshots
Checklist
bun run lint:backend && bun run lint.accordingly.
my tests
Created with PostHog Desktop from this inbox report.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
metadataoption is now interpreted asversion_number.