File tree Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Original file line number Diff line number Diff line change 1010 Dict ,
1111 ForwardRef ,
1212 Generator ,
13+ Literal ,
1314 Mapping ,
1415 Optional ,
1516 Set ,
2223from pydantic import BaseModel
2324from pydantic .fields import FieldInfo
2425from typing_extensions import Annotated , get_args , get_origin
26+ from .sql .sqltypes import AutoString
2527
2628# Reassign variable to make it reexported for mypy
2729PYDANTIC_VERSION = P_VERSION
@@ -458,10 +460,12 @@ def is_field_noneable(field: "FieldInfo") -> bool:
458460 )
459461 return field .allow_none # type: ignore[no-any-return, attr-defined]
460462
461- def get_sa_type_from_field (field : Any ) -> Any :
462- if isinstance (field .type_ , type ) and field .shape == SHAPE_SINGLETON :
463- return field .type_
464- raise ValueError (f"The field { field .name } has no matching SQLAlchemy type" )
463+ # def get_sa_type_from_field(field: Any) -> Any:
464+ # if field is Literal:
465+ # return AutoString
466+ # elif isinstance(field.type_, type) and field.shape == SHAPE_SINGLETON:
467+ # return field.type_
468+ # raise ValueError(f"The field {field.name} has no matching SQLAlchemy type")
465469
466470 def get_field_metadata (field : Any ) -> Any :
467471 metadata = FakeMetadata ()
Original file line number Diff line number Diff line change @@ -135,15 +135,15 @@ class Hero(SQLModel, table=True):
135135 name : str = Field (unique = True )
136136 weakness : Literal ["Kryptonite" , "Dehydration" , "Munchies" ]
137137
138- superman = Hero (name = "Superman " , weakness = "Kryptonite" )
138+ superguy = Hero (name = "Superguy " , weakness = "Kryptonite" )
139139
140140 engine = create_engine ("sqlite://" , echo = True )
141141
142142 SQLModel .metadata .create_all (engine )
143143
144144 with Session (engine ) as session :
145- session .add (superman )
145+ session .add (superguy )
146146 session .commit ()
147- session .refresh (superman )
148- assert superman .weakness == "Kryptonite"
149- assert isinstance (superman .weakness , str )
147+ session .refresh (superguy )
148+ assert superguy .weakness == "Kryptonite"
149+ assert isinstance (superguy .weakness , str )
You can’t perform that action at this time.
0 commit comments