Skip to content

fix: column field singularization, duplicate parameter names, sequence args typing#164

Open
Mic92 wants to merge 4 commits into
rayakame:mainfrom
Mic92:fix-codegen-shortcomings
Open

fix: column field singularization, duplicate parameter names, sequence args typing#164
Mic92 wants to merge 4 commits into
rayakame:mainfrom
Mic92:fix-codegen-shortcomings

Conversation

@Mic92

@Mic92 Mic92 commented Jun 9, 2026

Copy link
Copy Markdown

I hit three codegen bugs while using the plugin with asyncpg, fixed in separate commits:

Field names get singularized. My schema has an outputs jsonb column and the generated row classes called the field output, so it no longer matched the column. Looks like the table-name inflection was accidentally applied to column names too. While fixing this I noticed the duplicate-column suffix was computed but never applied to the emitted name, so something like

SELECT a.outputs, b.outputs FROM ...

generated a class with two identical fields. Both fixed; embed fields keep the singular naming since those represent a row, not a column.

Duplicate function parameters. I had a query using $2 in one place and sqlc.arg(status) in another, and got:

async def set_build_status(conn, *, id_: int, status: str, ..., status: str) -> None:

Now the second one becomes status_2.

QueryResultsArgsType doesn't allow sequences, but asyncpg takes array parameters (text[] etc.) as Python sequences, so every :many query with an array param fails pyright/mypy. Added collections.abc.Sequence[typing.Any] to the union.

Heads up on the first fix: anyone with plural column names gets renamed fields after this (they get the actual column names). That's the point of the fix, but it will show up as a diff in regenerated code.

Mic92 added 4 commits June 9, 2026 22:04
Field names went through the same inflection as table names: a query
selecting an "outputs" column got an "output" field that no longer
matched the database column. The duplicate-column suffix was also
computed but never applied, so two same-named selected columns
produced a class with duplicate fields.

Use the column name as-is, plus the duplicate suffix. Embedded
fields stay singularized: they hold one row of the joined table, not
a column.
A query mixing a positional reference ($2) with a same-named
sqlc.arg() emitted two function parameters with the same name, which
is not valid Python.
asyncpg passes array parameters (e.g. text[]) as Python sequences;
:many queries taking them failed type checking against the
QueryResults *args annotation.
Plural column names stay as-is, duplicate selected columns get
suffixed fields, and a positional + same-named sqlc.arg() mix
generates distinct parameters. Outputs regenerated with the rebuilt
plugin.
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Mic92, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 58 minutes and 5 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3c4ccea7-965d-4b8c-ab83-11c38d4744af

📥 Commits

Reviewing files that changed from the base of the PR and between 7746675 and 3a5fbeb.

⛔ Files ignored due to path filters (3)
  • test/driver_aiosqlite/sqlc-gen-better-python.wasm is excluded by !**/*.wasm
  • test/driver_asyncpg/sqlc-gen-better-python.wasm is excluded by !**/*.wasm
  • test/driver_sqlite3/sqlc-gen-better-python.wasm is excluded by !**/*.wasm
📒 Files selected for processing (64)
  • .changes/unreleased/Fixed-duplicate-params.yaml
  • .changes/unreleased/Fixed-field-singularization.yaml
  • .changes/unreleased/Fixed-queryresults-sequence.yaml
  • internal/builders.go
  • internal/core/importer.go
  • test/driver_aiosqlite/attrs/classes/__init__.py
  • test/driver_aiosqlite/attrs/classes/models.py
  • test/driver_aiosqlite/attrs/classes/queries.py
  • test/driver_aiosqlite/attrs/functions/__init__.py
  • test/driver_aiosqlite/attrs/functions/models.py
  • test/driver_aiosqlite/attrs/functions/queries.py
  • test/driver_aiosqlite/dataclass/classes/__init__.py
  • test/driver_aiosqlite/dataclass/classes/models.py
  • test/driver_aiosqlite/dataclass/classes/queries.py
  • test/driver_aiosqlite/dataclass/functions/__init__.py
  • test/driver_aiosqlite/dataclass/functions/models.py
  • test/driver_aiosqlite/dataclass/functions/queries.py
  • test/driver_aiosqlite/msgspec/classes/__init__.py
  • test/driver_aiosqlite/msgspec/classes/models.py
  • test/driver_aiosqlite/msgspec/classes/queries.py
  • test/driver_aiosqlite/msgspec/functions/__init__.py
  • test/driver_aiosqlite/msgspec/functions/models.py
  • test/driver_aiosqlite/msgspec/functions/queries.py
  • test/driver_aiosqlite/sqlc.yaml
  • test/driver_asyncpg/attrs/classes/__init__.py
  • test/driver_asyncpg/attrs/classes/models.py
  • test/driver_asyncpg/attrs/classes/queries.py
  • test/driver_asyncpg/attrs/functions/__init__.py
  • test/driver_asyncpg/attrs/functions/models.py
  • test/driver_asyncpg/attrs/functions/queries.py
  • test/driver_asyncpg/dataclass/classes/__init__.py
  • test/driver_asyncpg/dataclass/classes/models.py
  • test/driver_asyncpg/dataclass/classes/queries.py
  • test/driver_asyncpg/dataclass/functions/__init__.py
  • test/driver_asyncpg/dataclass/functions/models.py
  • test/driver_asyncpg/dataclass/functions/queries.py
  • test/driver_asyncpg/msgspec/classes/__init__.py
  • test/driver_asyncpg/msgspec/classes/models.py
  • test/driver_asyncpg/msgspec/classes/queries.py
  • test/driver_asyncpg/msgspec/functions/__init__.py
  • test/driver_asyncpg/msgspec/functions/models.py
  • test/driver_asyncpg/msgspec/functions/queries.py
  • test/driver_asyncpg/queries.sql
  • test/driver_asyncpg/schema.sql
  • test/driver_asyncpg/sqlc.yaml
  • test/driver_sqlite3/attrs/classes/__init__.py
  • test/driver_sqlite3/attrs/classes/models.py
  • test/driver_sqlite3/attrs/classes/queries.py
  • test/driver_sqlite3/attrs/functions/__init__.py
  • test/driver_sqlite3/attrs/functions/models.py
  • test/driver_sqlite3/attrs/functions/queries.py
  • test/driver_sqlite3/dataclass/classes/__init__.py
  • test/driver_sqlite3/dataclass/classes/models.py
  • test/driver_sqlite3/dataclass/classes/queries.py
  • test/driver_sqlite3/dataclass/functions/__init__.py
  • test/driver_sqlite3/dataclass/functions/models.py
  • test/driver_sqlite3/dataclass/functions/queries.py
  • test/driver_sqlite3/msgspec/classes/__init__.py
  • test/driver_sqlite3/msgspec/classes/models.py
  • test/driver_sqlite3/msgspec/classes/queries.py
  • test/driver_sqlite3/msgspec/functions/__init__.py
  • test/driver_sqlite3/msgspec/functions/models.py
  • test/driver_sqlite3/msgspec/functions/queries.py
  • test/driver_sqlite3/sqlc.yaml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Mic92 Mic92 force-pushed the fix-codegen-shortcomings branch from 45d0a68 to 3a5fbeb Compare June 9, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant