Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Invalid name generation when using python reserved keywords #88

Copy link
Copy link
@QuentinN42

Description

@QuentinN42
Issue body actions

Given the following SQL schema:

CREATE TABLE authors (
          id    BIGSERIAL PRIMARY KEY,
          class text      NOT NULL
);

sqlc will generate the following python code :

class Author(pydantic.BaseModel):
    id: int
    class: str

This is not a valid python code :

>>> import pydantic
... 
... 
... class Author(pydantic.BaseModel):
...     id: int
...     class: str
... 
  File "<python-input-0>", line 6
    class: str
         ^
SyntaxError: invalid syntax

This is due to class to be a reserved python keyword.
Note that it will also fails if you use if, not, in, etc...

I have generated an example on my fork: https://github.com/Escape-Technologies/sqlc-gen-python/tree/19e8d56813a83664bc19c12a3121e84e8bc7af66/internal/endtoend/testdata/emit_pydantic_models_with_fields

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.