Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f7d86ec
📝 Fix type alias handling in _compat.py
stickm4n Oct 28, 2025
a7615de
📝 Add tests for type alias handling in test_field_sa_type.py
stickm4n Oct 28, 2025
105a8e5
📝 Update type alias definitions in tests and compatibility module for…
stickm4n Oct 29, 2025
9d63657
📝 Update type alias handling for Python 3.12 compatibility
stickm4n Oct 29, 2025
5954463
📝 Refactor tests in test_field_sa_type.py for Python 3.12 compatibility
stickm4n Oct 29, 2025
69a2b21
📝 Enhance type alias handling in compatibility module and tests for P…
stickm4n Oct 29, 2025
05d32da
📝 Remove Python 3.12 compatibility marker from tests in test_field_sa…
stickm4n Oct 29, 2025
a05a685
📝 Add handling for GenericAlias in type alias checks for Python 3.10
stickm4n Oct 29, 2025
fc9a2e6
📝 Refactor type alias handling and add tests for NewType and TypeVar …
stickm4n Oct 29, 2025
506e5c1
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] Oct 29, 2025
80f7a09
📝 Fix type alias check to ensure check_type is not empty before valid…
stickm4n Oct 29, 2025
a2303b3
Merge remote-tracking branch 'origin/type-alias-fix' into type-alias-fix
stickm4n Oct 29, 2025
8fe139b
📝 Fix type alias check to ensure check_type is not empty before valid…
stickm4n Oct 29, 2025
563fa92
📝 Update type alias definitions to support conditional assignment for…
stickm4n Oct 29, 2025
a86418c
📝 Update tests to conditionally define type aliases based on availabi…
stickm4n Oct 29, 2025
daadf43
📝 Update _is_new_type_instance to handle Python 3.10 compatibility
stickm4n Oct 29, 2025
d128318
📝 Add needs_pydanticv2 decorator to tests for Pydantic v2 compatibility
stickm4n Oct 29, 2025
1e9cf12
📝 Refactor type alias handling to improve compatibility with Python 3…
stickm4n Oct 29, 2025
2cc8cd0
Update _compat.py
stickm4n Oct 30, 2025
702ac38
Update _compat.py
stickm4n Oct 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sqlmodel/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def partial_init() -> Generator[None, None, None]:


if IS_PYDANTIC_V2:
if sys.version_info >= (3, 12):
from typing import TypeAliasType

from annotated_types import MaxLen
from pydantic import ConfigDict as BaseConfig
from pydantic._internal._fields import PydanticMetadata
Expand Down Expand Up @@ -203,6 +206,8 @@ def get_sa_type_from_type_annotation(annotation: Any) -> Any:
# Resolve Optional fields
if annotation is None:
raise ValueError("Missing field type")
if sys.version_info >= (3, 12) and isinstance(annotation, TypeAliasType):
annotation = annotation.__value__
origin = get_origin(annotation)
if origin is None:
return annotation
Expand Down
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,6 @@ def print_mock_fixture() -> Generator[PrintMock, None, None]:
needs_py310 = pytest.mark.skipif(
sys.version_info < (3, 10), reason="requires python3.10+"
)
needs_py312 = pytest.mark.skipif(
sys.version_info < (3, 12), reason="requires python3.12+"
)
63 changes: 63 additions & 0 deletions tests/test_field_sa_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import sys
from typing import Annotated, TypeAlias

from sqlmodel import Field, SQLModel

from tests.conftest import needs_py312


@needs_py312
def test_sa_type_1() -> None:
Type1 = str

class Hero1(SQLModel, table=True):
pk: int = Field(primary_key=True)
weapon: Type1 = "sword"


@needs_py312
def test_sa_type_2() -> None:
Type2 = Annotated[str, "Just a comment"]

class Hero(SQLModel, table=True):
pk: int = Field(primary_key=True)
weapon: Type2 = "sword"


Type3: TypeAlias = str


@needs_py312
def test_sa_type_3() -> None:
class Hero(SQLModel, table=True):
pk: int = Field(primary_key=True)
weapon: Type3 = "sword"


Type4: TypeAlias = Annotated[str, "Just a comment"]


@needs_py312
def test_sa_type_4() -> None:
class Hero(SQLModel, table=True):
pk: int = Field(primary_key=True)
weapon: Type4 = "sword"


if sys.version_info >= (3, 12):

@needs_py312
def test_sa_type_5() -> None:
type Type5 = str

class Hero(SQLModel, table=True):
pk: int = Field(primary_key=True)
weapon: Type5 = "sword"

@needs_py312
def test_sa_type_6() -> None:
type Type6 = Annotated[str, "Just a comment"]

class Hero(SQLModel, table=True):
pk: int = Field(primary_key=True)
weapon: Type6 = "sword"
Loading