File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -738,7 +738,24 @@ def get_sqlalchemy_type(field: Any) -> Any:
738738 raise ValueError (f"{ type_ } has no matching SQLAlchemy type" )
739739
740740
741+ def _create_union (args : tuple [Any , ...]) -> Any | Any :
742+ if len (args ) == 1 :
743+ return args [0 ]
744+ return args [0 ] | _create_union (args [1 :])
745+
746+
741747def get_column_from_field (field : Any ) -> Column : # type: ignore
748+ if isinstance (field .annotation , TypeVar ):
749+ generic : TypeVar = field .annotation
750+ if generic .__bound__ is not None :
751+ field .annotation = generic .__bound__
752+ elif generic .__constraints__ != ():
753+ constraints = generic .__constraints__
754+ field .annotation = _create_union (constraints )
755+ else :
756+ raise TypeError (
757+ f"Invalid type used for { field } . Please define a bound or constraints."
758+ )
742759 field_info = field
743760 sa_column = _get_sqlmodel_field_value (field_info , "sa_column" , Undefined )
744761 if isinstance (sa_column , Column ):
You can’t perform that action at this time.
0 commit comments