fix(postgrest-typegen): escape Go struct tags for pathological column names - #122
Open
spydon wants to merge 2 commits into
Open
fix(postgrest-typegen): escape Go struct tags for pathological column names#122spydon wants to merge 2 commits into
spydon wants to merge 2 commits into
Conversation
… names Go struct tags were interpolated into raw string literals verbatim, so a column name containing a backtick terminated the literal early and the generated source failed to parse. Names containing double quotes or backslashes compiled but produced tags that reflect.StructTag could not round-trip. Column and composite attribute names are now quoted with JSON.stringify, whose escape sequences are a subset of Go's, so reflect.StructTag.Get recovers the exact name. Ordinary names keep their previous raw literal representation; only names containing a backtick fall back to an interpreted literal, since Go raw literals cannot contain one. Validated against the Go toolchain: generated structs for names with backticks, quotes, backslashes and control characters parse under gofmt and round-trip through reflect.StructTag.Get. Ported from supabase/postgres-meta#1127 and supabase/postgres-meta#1131.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Aug 31, 2026
Tr00d
approved these changes
Aug 31, 2026
…g-shaped names encoding/json does not fall back to the Go field name for every name it cannot represent: a comma splits the name from tag options, so only the part before it is used. Reword the formatForGoStructTag docstring to match the verified runtime behavior and add regression tests for a column name shaped like a full json tag and for a control character escape inside the interpreted-literal fallback.
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
Ports the Go struct tag escaping fix from postgres-meta's open template PRs into this package (the templates are being deleted in favor of this package in supabase/postgres-meta#1084, so open fixes there are triaged and re-landed here).
A backtick in a column name terminated the raw struct tag literal and produced unparseable Go (supabase/postgres-meta#1125). Tag values are now built with
JSON.stringify(JSON escape sequences are a strict subset of Go's, soreflect.StructTag.Getrecovers the exact name viastrconv.Unquote), and tags containing a backtick fall back to an interpreted string literal. Ordinary names keep the exact raw-literal form, so normal output is byte-identical and the parity golden is unchanged.Triage of origin PRs
JSON.stringifyescaping precedent.a"bproduced a tag thatreflect.StructTag.Getmisparses (its own test pins the broken output).Known limitation, documented in the code: names that
encoding/jsonitself rejects as tag names (commas, quotes, backticks) still compile and round-trip throughreflect.StructTag, but the marshaler falls back to the Go field name at runtime; that is a limitation of the struct tag convention, not the generated source. Output for the pathological cases was validated against real Go (gofmt parse +reflect.StructTag.Getround-trip).Validation
check-types,format-and-lint,knip,build,test(100 pass, including Docker-backed parity) all green.