fix(orgtoken): cast org_id to text in COALESCE (prevents /org/tokens 500) - #1696
Merged
Conversation
Symptom (prod tenant hongmingwang): GET /org/tokens → 500 orgtoken list: orgtoken: list: pq: invalid input syntax for type uuid: "" Postgres rejects COALESCE(uuid_col, '') because it can't cast the empty string to UUID. Cast to ::text first so the COALESCE operates on matching types. OrgID on the Go side is already string, so no scan changes needed. sqlmock doesn't exercise pq type coercion — it accepts any AddRow value for any column — which is why the existing tests pass while prod 500s. Real-Postgres integration coverage is the systemic fix (tracked separately), but this PR unblocks the Settings → Org Tokens page today. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
HongmingWang-Rabbit
pushed a commit
that referenced
this pull request
Jun 12, 2026
#1698) Co-authored-by: agent-dev-a <agent-dev-a@agents.moleculesai.app> Co-committed-by: agent-dev-a <agent-dev-a@agents.moleculesai.app>
HongmingWang-Rabbit
pushed a commit
that referenced
this pull request
Jun 12, 2026
…nses (#1699) Co-authored-by: agent-dev-b <agent-dev-b@agents.moleculesai.app> Co-committed-by: agent-dev-b <agent-dev-b@agents.moleculesai.app>
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
orgtoken.ListqueriesCOALESCE(org_id,'')butorg_idis a UUID column — Postgres can't cast''to UUID, fails withpq: invalid input syntax for type uuid: ""COALESCE(org_id::text,'')— operates on matching typesToken.OrgIDis alreadystring, scan still worksSymptom (prod, hongmingwang)
Tenant Settings → Org Tokens page broken.
Why tests didn't catch it
sqlmock (used in
tokens_test.go) doesn't model the pq driver's type coercion. It accepts any AddRow value for any declared column, so the query-level type mismatch is invisible. Real fix needs a real-Postgres integration harness; filed as follow-up.Test plan
go test ./internal/orgtoken/— existing tests still pass (regexSELECT id, prefix.*FROM org_api_tokens.*ORDER BY created_at DESCstill matches)SELECT COALESCE(org_id::text,'') FROM org_api_tokens LIMIT 5executes without errorAudit
Searched for sibling
COALESCE(uuid_col, '')patterns across workspace-server. Only one other hit:terminal.gousesCOALESCE(instance_id, '')butinstance_idis text (EC2 IDs likei-xxx), not UUID — safe.🤖 Generated with Claude Code