Skip to content
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

Some fields are translated as JSON fields even though they shouldn't be #43

Closed
iron3oxide opened this issue Oct 11, 2022 · 1 comment · Fixed by #44
Closed

Some fields are translated as JSON fields even though they shouldn't be #43

iron3oxide opened this issue Oct 11, 2022 · 1 comment · Fixed by #44

Comments

@iron3oxide
Copy link
Contributor

I have the following setup:

A table base model

class TableBase(BaseModel):
    id: int = Field(default=1, gt=0)
    created_by: str
    created_at: datetime = Field(default_factory=datetime.now)
    last_modified_by: str = Field(default="not_yet_modified")
    last_modified_at: datetime | None = Field(default=None)

and the final tables inheriting from the table base and the respective read model, e.g.:

@db.table(pk="id")
class Language(LanguageRead, TableBase):
    pass

When I call db.init() I get an sqlalchemy ProgrammingError and it shows me the following SQL as the culprit:

CREATE TABLE language (
        id JSON, 
        created_by VARCHAR NOT NULL, 
        created_at JSON, 
        last_modified_by VARCHAR, 
        last_modified_at JSON, 
        name VARCHAR NOT NULL, 
        PRIMARY KEY (id)
)

The issue is probably in PydanticSQLTableGenerator._get_column() but I couldn't figure out why my model fields would be caught by one of the cases specified for JSON there. Any help is appreciated!

@iron3oxide
Copy link
Contributor Author

One initial observation though: at the moment, there seems to be no way to translate date/datetime fields of any kind to their respective sqlalchemy counterparts, this should be an easy addition.

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 a pull request may close this issue.

1 participant