FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

✨ Raise an exception when using a Pydantic field type with no matching SQLAlchemy type by elben10 · Pull Request #18 · fastapi/sqlmodel · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions sqlmodel/main.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
Expand Up @@ -415,6 +415,7 @@ def get_sqlachemy_type(field: ModelField) -> Any:
return AutoString
if issubclass(field.type_, uuid.UUID):
return GUID
raise ValueError(f"The field {field.name} has no matching SQLAlchemy type")


def get_column_from_field(field: ModelField) -> Column: # type: ignore
Expand Down
21 changes: 21 additions & 0 deletions tests/test_missing_type.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,21 @@
from typing import Optional

import pytest
from sqlmodel import Field, SQLModel


def test_missing_sql_type():
class CustomType:
@classmethod
def __get_validators__(cls):
yield cls.validate

@classmethod
def validate(cls, v):
return v

with pytest.raises(ValueError):

class Item(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
item: CustomType

Back | FazBrowse Home | New Git URL