Repository navigation
fix(postgrest-typegen): python escaping, 3.9 imports, JsonValue json columns, composite nullability - #124
Merged
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team 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
|
Thank you for porting the fix and crediting PR supabase/supabase-py#1094. I’ll follow the shared type-generation implementation in supabase/supabase-py#124. |
Enum labels and column aliases were interpolated into the generated Python source unescaped, so a name containing a double quote, backslash or newline produced invalid Python and could inject text into the generated module. Emit them through JSON string escaping, which is a subset of Python's string literal escaping. Ported from supabase/postgres-meta#1082
…extensions NotRequired only exists in typing from Python 3.11 and TypeAlias from 3.10, so the generated module failed to import on Python 3.9 and 3.10. typing_extensions ships them for all supported versions and is already a required dependency of pydantic, so the import is always available. Ported from supabase/postgres-meta#1094
…thon pydantic's Json[Any] validates a JSON string and deserializes it, but PostgREST returns json and jsonb columns already deserialized, so every generated model with a JSON column failed model_validate. JsonValue is pydantic's type for an already parsed JSON value. Ported from supabase/postgres-meta#1129
Postgres composite type attributes cannot carry NOT NULL constraints, so every field is inherently nullable, yet the generated Python models declared them as required non-None fields and rejected valid rows. Ported from supabase/postgres-meta#1063 (the Python side of the same nullability bug; the upstream PR only implemented the TypeScript part)
spydon
force-pushed
the
fix/typegen-python-fixes
branch
from
September 1, 2026 08:12
2954da8 to
76f2903
Compare
spydon
pushed a commit
that referenced
this pull request
Sep 2, 2026
🤖 I have created a release *beep* *boop* --- ## [0.2.1](postgrest-typegen-v0.2.0...postgrest-typegen-v0.2.1) (2026-09-02) ### Bug Fixes * **postgrest-typegen:** escape database values in Swift string literals ([#123](#123)) ([4a5cef5](4a5cef5)) * **postgrest-typegen:** escape Go struct tags for pathological column names ([#122](#122)) ([42c0249](42c0249)) * **postgrest-typegen:** generated columns, NonNullable json, zero-arg Args, trigger-writable views ([#125](#125)) ([67650c6](67650c6)) * **postgrest-typegen:** inline pg-format literal and drop the dependency ([#138](#138)) ([2c16a15](2c16a15)) * **postgrest-typegen:** python escaping, 3.9 imports, JsonValue json columns, composite nullability ([#124](#124)) ([d1f9b3b](d1f9b3b)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com>
spydon
added a commit
that referenced
this pull request
Sep 16, 2026
…eta (#192) ## Why The scheduled "Parity vs. real postgres-meta" job in `postgrest-typegen-validate.yml` has failed every night since 2026-09-10 (SDK-1847). The ticket assumed postgres-meta had changed its Python template after the cutover. It is the other way around: postgres-meta deleted its templates in supabase/postgres-meta#1084 (postgres-meta v0.99.0, 2026-08-31) and now consumes `@supabase/postgrest-typegen`, with its lockfile pinned to `0.2.0`. The job therefore diffs `main` against our own `0.2.0` release as installed by postgres-meta's `npm ci`. Every intentional generator change since then shows up as "drift": - Python `JsonValue`, `typing_extensions` imports, and `Optional[...]` composite attributes (#124, released in 0.2.1). In the diff, the `-` lines are postgres-meta's output and the `+` lines are ours. - TypeScript fixed-collation ordering (#181, released in 0.2.2), which started failing today's run as well. There is no independent upstream left to compare against. Comparing against postgres-meta only measures how far behind its pinned version is, and postgres-meta's own snapshot tests cover its adapter. ## What - Remove the `parity-check` job and the `schedule` and `workflow_dispatch` triggers that only existed for it; the remaining `test` job runs on push and pull requests as before. - Delete `scripts/load-fixtures.ts`, `scripts/print-generated.ts`, and `scripts/canonicalize-typescript.ts`, which only served that job, and drop their knip entries. - Replace the "Byte-Parity Constraint" section in the package `CLAUDE.md` with a description of the post-cutover relationship (this package is the single source of truth; output changes are behavior changes for postgres-meta and the CLI, reviewed via the regenerated snapshots and goldens). Adjust the README and the golden test's doc comment to match. The `prettier` pin note was already stale since the package has no prettier dependency. The golden test under `test/parity/` and its `expected/` files stay as the in-repo regression gate. ## Verification `bun run check-types`, `bun run format-and-lint`, `bun run knip`, and `bun run test` (134 tests, including the testcontainers-backed golden test) pass locally. Closes SDK-1847.
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 worthwhile Python generator fixes 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). Four fixes, one commit each:
Literallabels andField(alias=...)values were interpolated unescaped, so a quote, backslash, or newline in a database name broke the generated module. A sharedescapePythonStringhelper (JSON escaping, a strict subset of Python's) now covers all three interpolation sites.NotRequired(3.11+) andTypeAlias(3.10+) now import fromtyping_extensions, which is always installed as a required dependency of pydantic.json/jsonbmap to pydantic'sJsonValueinstead ofJson[Any]. PostgREST returns these columns already deserialized, whileJson[Any]validates a JSON string and parses it, so every generated model with a JSON column failedmodel_validate(Json columns don't deserialize correctly #250).Optional[...]. The origin PR's Python hunks were dead code (an unusedPythonDomainclass and a type-map entry for a name Postgres never emits), so the actual fix was implemented instead of ported.Triage of origin PRs
JsonValueis pydantic's native type for a parsed JSON value.typeToClass.frozen=True)Validation
Optionalfields).typing_extensionsimport split, 16Json[Any]toJsonValueoccurrences, and two composite attributes gainingOptional[...]; reviewed line by line and the golden gate was verified to actually trip on corruption.mypy, and runtime checks confirm deserialized JSON andNonecomposite fields now validate.check-types,format-and-lint,knip,build,test(97 pass, includes Docker-backed introspection and parity) all green.