-
Notifications
You must be signed in to change notification settings - Fork 40
Invalid name generation when using python reserved keywords #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
QuentinN42
wants to merge
5
commits into
sqlc-dev:main
Choose a base branch
from
Escape-Technologies:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
19e8d56
feat: added invalid test for invalid name generation when using pytho…
QuentinN42 f928244
fix: added reserved python keywords
QuentinN42 24fcd39
refactor: use poet.Node
QuentinN42 a5d1ee8
test: added more tests to the poet pkg and generated the pydantic.Con…
QuentinN42 068fd25
feat: added dataclasses tests
QuentinN42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # Code generated by sqlc. DO NOT EDIT. | ||
| # versions: | ||
| # sqlc v1.28.0 | ||
| # sqlc v1.29.0 | ||
| import dataclasses | ||
|
|
||
|
|
||
|
|
||
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
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
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
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
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
Empty file.
10 changes: 10 additions & 0 deletions
10
internal/endtoend/testdata/dataclasses_with_reserved_keywords/db/models.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Code generated by sqlc. DO NOT EDIT. | ||
| # versions: | ||
| # sqlc v1.29.0 | ||
| import dataclasses | ||
|
|
||
|
|
||
| @dataclasses.dataclass() | ||
| class Author: | ||
| id: int | ||
| class_: str |
44 changes: 44 additions & 0 deletions
44
internal/endtoend/testdata/dataclasses_with_reserved_keywords/db/query.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Code generated by sqlc. DO NOT EDIT. | ||
| # versions: | ||
| # sqlc v1.29.0 | ||
| # source: query.sql | ||
| from typing import Optional | ||
|
|
||
| import sqlalchemy | ||
| import sqlalchemy.ext.asyncio | ||
|
|
||
| from db import models | ||
|
|
||
|
|
||
| GET_AUTHOR = """-- name: get_author \\:one | ||
| SELECT id, class FROM authors | ||
| WHERE id = :p1 LIMIT 1 | ||
| """ | ||
|
|
||
|
|
||
| class Querier: | ||
| def __init__(self, conn: sqlalchemy.engine.Connection): | ||
| self._conn = conn | ||
|
|
||
| def get_author(self, *, id: int) -> Optional[models.Author]: | ||
| row = self._conn.execute(sqlalchemy.text(GET_AUTHOR), {"p1": id}).first() | ||
| if row is None: | ||
| return None | ||
| return models.Author( | ||
| id=row[0], | ||
| class_=row[1], | ||
| ) | ||
|
|
||
|
|
||
| class AsyncQuerier: | ||
| def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): | ||
| self._conn = conn | ||
|
|
||
| async def get_author(self, *, id: int) -> Optional[models.Author]: | ||
| row = (await self._conn.execute(sqlalchemy.text(GET_AUTHOR), {"p1": id})).first() | ||
| if row is None: | ||
| return None | ||
| return models.Author( | ||
| id=row[0], | ||
| class_=row[1], | ||
| ) |
3 changes: 3 additions & 0 deletions
3
internal/endtoend/testdata/dataclasses_with_reserved_keywords/query.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| -- name: GetAuthor :one | ||
| SELECT * FROM authors | ||
| WHERE id = $1 LIMIT 1; |
4 changes: 4 additions & 0 deletions
4
internal/endtoend/testdata/dataclasses_with_reserved_keywords/schema.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| CREATE TABLE authors ( | ||
| id BIGSERIAL PRIMARY KEY, | ||
| class text NOT NULL | ||
| ); |
18 changes: 18 additions & 0 deletions
18
internal/endtoend/testdata/dataclasses_with_reserved_keywords/sqlc.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| version: "2" | ||
| plugins: | ||
| - name: py | ||
| wasm: | ||
| url: file://../../../../bin/sqlc-gen-python.wasm | ||
| sha256: "24b0da217e85c9b952a4c746476aa761e9b293a4a68bef8409d97edc1c003016" | ||
| sql: | ||
| - schema: schema.sql | ||
| queries: query.sql | ||
| engine: postgresql | ||
| codegen: | ||
| - plugin: py | ||
| out: db | ||
| options: | ||
| package: db | ||
| emit_sync_querier: true | ||
| emit_async_querier: true | ||
| emit_pydantic_models: false |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,15 @@ | ||
| # Code generated by sqlc. DO NOT EDIT. | ||
| # versions: | ||
| # sqlc v1.28.0 | ||
| # sqlc v1.29.0 | ||
| import pydantic | ||
| from typing import Optional | ||
|
|
||
|
|
||
| class Author(pydantic.BaseModel): | ||
| model_config = pydantic.ConfigDict( | ||
| validate_by_alias=True, | ||
| validate_by_name=True, | ||
| ) | ||
| id: int | ||
| name: str | ||
| bio: Optional[str] |
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
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
Empty file.
15 changes: 15 additions & 0 deletions
15
internal/endtoend/testdata/emit_pydantic_models_with_reserved_keywords/db/models.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Code generated by sqlc. DO NOT EDIT. | ||
| # versions: | ||
| # sqlc v1.29.0 | ||
| import pydantic | ||
|
|
||
|
|
||
| class Author(pydantic.BaseModel): | ||
| model_config = pydantic.ConfigDict( | ||
| validate_by_alias=True, | ||
| validate_by_name=True, | ||
| ) | ||
| id: int | ||
| class_: str = pydantic.Field( | ||
| alias="class", | ||
| ) |
44 changes: 44 additions & 0 deletions
44
internal/endtoend/testdata/emit_pydantic_models_with_reserved_keywords/db/query.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Code generated by sqlc. DO NOT EDIT. | ||
| # versions: | ||
| # sqlc v1.29.0 | ||
| # source: query.sql | ||
| from typing import Optional | ||
|
|
||
| import sqlalchemy | ||
| import sqlalchemy.ext.asyncio | ||
|
|
||
| from db import models | ||
|
|
||
|
|
||
| GET_AUTHOR = """-- name: get_author \\:one | ||
| SELECT id, class FROM authors | ||
| WHERE id = :p1 LIMIT 1 | ||
| """ | ||
|
|
||
|
|
||
| class Querier: | ||
| def __init__(self, conn: sqlalchemy.engine.Connection): | ||
| self._conn = conn | ||
|
|
||
| def get_author(self, *, id: int) -> Optional[models.Author]: | ||
| row = self._conn.execute(sqlalchemy.text(GET_AUTHOR), {"p1": id}).first() | ||
| if row is None: | ||
| return None | ||
| return models.Author( | ||
| id=row[0], | ||
| class_=row[1], | ||
| ) | ||
|
|
||
|
|
||
| class AsyncQuerier: | ||
| def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): | ||
| self._conn = conn | ||
|
|
||
| async def get_author(self, *, id: int) -> Optional[models.Author]: | ||
| row = (await self._conn.execute(sqlalchemy.text(GET_AUTHOR), {"p1": id})).first() | ||
| if row is None: | ||
| return None | ||
| return models.Author( | ||
| id=row[0], | ||
| class_=row[1], | ||
| ) |
3 changes: 3 additions & 0 deletions
3
internal/endtoend/testdata/emit_pydantic_models_with_reserved_keywords/query.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| -- name: GetAuthor :one | ||
| SELECT * FROM authors | ||
| WHERE id = $1 LIMIT 1; |
4 changes: 4 additions & 0 deletions
4
internal/endtoend/testdata/emit_pydantic_models_with_reserved_keywords/schema.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| CREATE TABLE authors ( | ||
| id BIGSERIAL PRIMARY KEY, | ||
| class text NOT NULL | ||
| ); |
18 changes: 18 additions & 0 deletions
18
internal/endtoend/testdata/emit_pydantic_models_with_reserved_keywords/sqlc.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| version: '2' | ||
| plugins: | ||
| - name: py | ||
| wasm: | ||
| url: file://../../../../bin/sqlc-gen-python.wasm | ||
| sha256: "24b0da217e85c9b952a4c746476aa761e9b293a4a68bef8409d97edc1c003016" | ||
| sql: | ||
| - schema: schema.sql | ||
| queries: query.sql | ||
| engine: postgresql | ||
| codegen: | ||
| - plugin: py | ||
| out: db | ||
| options: | ||
| package: db | ||
| emit_sync_querier: true | ||
| emit_async_querier: true | ||
| emit_pydantic_models: true |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # Code generated by sqlc. DO NOT EDIT. | ||
| # versions: | ||
| # sqlc v1.28.0 | ||
| # sqlc v1.29.0 | ||
| import dataclasses | ||
|
|
||
|
|
||
|
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # Code generated by sqlc. DO NOT EDIT. | ||
| # versions: | ||
| # sqlc v1.28.0 | ||
| # sqlc v1.29.0 | ||
| import dataclasses | ||
|
|
||
|
|
||
|
|
||
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
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
2 changes: 1 addition & 1 deletion
2
internal/endtoend/testdata/inflection_exclude_table_names/python/models.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # Code generated by sqlc. DO NOT EDIT. | ||
| # versions: | ||
| # sqlc v1.28.0 | ||
| # sqlc v1.29.0 | ||
| import dataclasses | ||
|
|
||
|
|
||
|
|
||
2 changes: 1 addition & 1 deletion
2
internal/endtoend/testdata/inflection_exclude_table_names/python/query.py
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
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
2 changes: 1 addition & 1 deletion
2
internal/endtoend/testdata/query_parameter_limit_two/python/models.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # Code generated by sqlc. DO NOT EDIT. | ||
| # versions: | ||
| # sqlc v1.28.0 | ||
| # sqlc v1.29.0 | ||
| import dataclasses | ||
|
|
||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change breaks the test logic. The error message should show
diff(the actual difference between want and got) to help debug test failures, notgot(the raw output). This makes it harder to understand what went wrong when tests fail.