1- from typing import Annotated , Optional
1+ from typing import Annotated
22
33import pytest
44from sqlalchemy import Column , Integer , String
77
88def test_sa_column_takes_precedence () -> None :
99 class Item (SQLModel , table = True ):
10- id : Optional [ int ] = Field (
10+ id : int | None = Field (
1111 default = None ,
1212 sa_column = Column (String , primary_key = True , nullable = False ),
1313 )
@@ -19,7 +19,7 @@ class Item(SQLModel, table=True):
1919
2020def test_sa_column_with_annotated_metadata () -> None :
2121 class Item (SQLModel , table = True ):
22- id : Annotated [Optional [ int ] , "meta" ] = Field (
22+ id : Annotated [int | None , "meta" ] = Field (
2323 default = None ,
2424 sa_column = Column (String , primary_key = True , nullable = False ),
2525 )
@@ -32,7 +32,7 @@ def test_sa_column_no_sa_args() -> None:
3232 with pytest .raises (RuntimeError ):
3333
3434 class Item (SQLModel , table = True ):
35- id : Optional [ int ] = Field (
35+ id : int | None = Field (
3636 default = None ,
3737 sa_column_args = [Integer ],
3838 sa_column = Column (Integer , primary_key = True ),
@@ -43,7 +43,7 @@ def test_sa_column_no_sa_kargs() -> None:
4343 with pytest .raises (RuntimeError ):
4444
4545 class Item (SQLModel , table = True ):
46- id : Optional [ int ] = Field (
46+ id : int | None = Field (
4747 default = None ,
4848 sa_column_kwargs = {"primary_key" : True },
4949 sa_column = Column (Integer , primary_key = True ),
@@ -54,7 +54,7 @@ def test_sa_column_no_type() -> None:
5454 with pytest .raises (RuntimeError ):
5555
5656 class Item (SQLModel , table = True ):
57- id : Optional [ int ] = Field (
57+ id : int | None = Field (
5858 default = None ,
5959 sa_type = Integer ,
6060 sa_column = Column (Integer , primary_key = True ),
@@ -65,7 +65,7 @@ def test_sa_column_no_primary_key() -> None:
6565 with pytest .raises (RuntimeError ):
6666
6767 class Item (SQLModel , table = True ):
68- id : Optional [ int ] = Field (
68+ id : int | None = Field (
6969 default = None ,
7070 primary_key = True ,
7171 sa_column = Column (Integer , primary_key = True ),
@@ -76,7 +76,7 @@ def test_sa_column_no_nullable() -> None:
7676 with pytest .raises (RuntimeError ):
7777
7878 class Item (SQLModel , table = True ):
79- id : Optional [ int ] = Field (
79+ id : int | None = Field (
8080 default = None ,
8181 nullable = True ,
8282 sa_column = Column (Integer , primary_key = True ),
@@ -87,12 +87,12 @@ def test_sa_column_no_foreign_key() -> None:
8787 with pytest .raises (RuntimeError ):
8888
8989 class Team (SQLModel , table = True ):
90- id : Optional [ int ] = Field (default = None , primary_key = True )
90+ id : int | None = Field (default = None , primary_key = True )
9191 name : str
9292
9393 class Hero (SQLModel , table = True ):
94- id : Optional [ int ] = Field (default = None , primary_key = True )
95- team_id : Optional [ int ] = Field (
94+ id : int | None = Field (default = None , primary_key = True )
95+ team_id : int | None = Field (
9696 default = None ,
9797 foreign_key = "team.id" ,
9898 sa_column = Column (Integer , primary_key = True ),
@@ -103,7 +103,7 @@ def test_sa_column_no_unique() -> None:
103103 with pytest .raises (RuntimeError ):
104104
105105 class Item (SQLModel , table = True ):
106- id : Optional [ int ] = Field (
106+ id : int | None = Field (
107107 default = None ,
108108 unique = True ,
109109 sa_column = Column (Integer , primary_key = True ),
@@ -114,7 +114,7 @@ def test_sa_column_no_index() -> None:
114114 with pytest .raises (RuntimeError ):
115115
116116 class Item (SQLModel , table = True ):
117- id : Optional [ int ] = Field (
117+ id : int | None = Field (
118118 default = None ,
119119 index = True ,
120120 sa_column = Column (Integer , primary_key = True ),
@@ -125,7 +125,7 @@ def test_sa_column_no_ondelete() -> None:
125125 with pytest .raises (RuntimeError ):
126126
127127 class Item (SQLModel , table = True ):
128- id : Optional [ int ] = Field (
128+ id : int | None = Field (
129129 default = None ,
130130 sa_column = Column (Integer , primary_key = True ),
131131 ondelete = "CASCADE" ,
0 commit comments