From a22dac8113d4086adc215ac5e9571da69f6e8f14 Mon Sep 17 00:00:00 2001 From: honglei Date: Mon, 14 Aug 2023 23:02:32 +0800 Subject: [PATCH] avoid get_args directly --- sqlmodel/main.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/sqlmodel/main.py b/sqlmodel/main.py index aa3def4..76f5aa6 100644 --- a/sqlmodel/main.py +++ b/sqlmodel/main.py @@ -24,8 +24,7 @@ from typing import ( Type, TypeVar, Union, - cast, - get_args + cast ) import types @@ -46,6 +45,8 @@ from sqlalchemy.orm.instrumentation import is_instrumented from sqlalchemy.orm.properties import MappedColumn from sqlalchemy.sql.schema import MetaData, DefaultClause from sqlalchemy.sql.sqltypes import LargeBinary, Time +from sqlalchemy.sql import false, true + from .sql.sqltypes import GUID, AutoString from .typing import SQLModelConfig @@ -179,8 +180,19 @@ def Field( #server_default -> default if isinstance(sa_column_, Column) and isinstance(sa_column_.server_default, DefaultClause): default_value = sa_column_.server_default.arg - if issubclass( type(sa_column_.type), Integer): + if issubclass( type(sa_column_.type), Integer) and isinstance(default_value, str): default = int(default_value) + elif issubclass( type(sa_column_.type), Boolean): + if default_value is false(): + default = False + elif default_value is true(): + default = True + elif isinstance(default_value, str): + if default_value == '1': + default =True + elif default_value == '0': + default = False + field_info = FieldInfo( default,