1- from typing import Optional
2-
31from sqlalchemy import ForeignKey , create_engine
42from sqlmodel import Field , SQLModel
53
64
75def test_base_model_fk (clear_sqlmodel , caplog ) -> None :
86 class User (SQLModel , table = True ):
9- id : Optional [ int ] = Field (default = None , primary_key = True )
7+ id : int | None = Field (default = None , primary_key = True )
108
119 class Base (SQLModel ):
12- owner_id : Optional [ int ] = Field (
10+ owner_id : int | None = Field (
1311 default = None , sa_column_args = (ForeignKey ("user.id" , ondelete = "SET NULL" ),)
1412 )
1513
1614 class Asset (Base , table = True ):
17- id : Optional [ int ] = Field (default = None , primary_key = True )
15+ id : int | None = Field (default = None , primary_key = True )
1816
1917 class Document (Base , table = True ):
20- id : Optional [ int ] = Field (default = None , primary_key = True )
18+ id : int | None = Field (default = None , primary_key = True )
2119
2220 engine = create_engine ("sqlite://" , echo = True )
2321 SQLModel .metadata .create_all (engine )
@@ -29,19 +27,19 @@ class Document(Base, table=True):
2927
3028def test_base_model_fk_args (clear_sqlmodel , caplog ) -> None :
3129 class User (SQLModel , table = True ):
32- id : Optional [ int ] = Field (default = None , primary_key = True )
30+ id : int | None = Field (default = None , primary_key = True )
3331
3432 class Base (SQLModel ):
35- owner_id : Optional [ int ] = Field (
33+ owner_id : int | None = Field (
3634 default = None ,
3735 foreign_key = ForeignKey ("user.id" , ondelete = "SET NULL" ),
3836 )
3937
4038 class Asset (Base , table = True ):
41- id : Optional [ int ] = Field (default = None , primary_key = True )
39+ id : int | None = Field (default = None , primary_key = True )
4240
4341 class Document (Base , table = True ):
44- id : Optional [ int ] = Field (default = None , primary_key = True )
42+ id : int | None = Field (default = None , primary_key = True )
4543
4644 engine = create_engine ("sqlite://" , echo = True )
4745 SQLModel .metadata .create_all (engine )
0 commit comments