From 27ae20a309214702328380e6a1d39ba6ed97ccd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernardo=20Jord=C3=A3o?= Date: Thu, 4 Apr 2024 21:23:24 +0100 Subject: [PATCH 1/2] use mysql's default string length for mariadb --- sqlmodel/sql/sqltypes.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sqlmodel/sql/sqltypes.py b/sqlmodel/sql/sqltypes.py index 5a4bb04ef1..72d95788cb 100644 --- a/sqlmodel/sql/sqltypes.py +++ b/sqlmodel/sql/sqltypes.py @@ -14,7 +14,9 @@ class AutoString(types.TypeDecorator): # type: ignore def load_dialect_impl(self, dialect: Dialect) -> "types.TypeEngine[Any]": impl = cast(types.String, self.impl) - if impl.length is None and dialect.name == "mysql": + if impl.length is None and ( + dialect.name == "mysql" or dialect.name == "mariadb" + ): return dialect.type_descriptor(types.String(self.mysql_default_length)) return super().load_dialect_impl(dialect) From 2dfc84cdc3726c807acfb272965d202fd5f9bbdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernardo=20Jord=C3=A3o?= Date: Sat, 13 Apr 2024 08:59:34 +0100 Subject: [PATCH 2/2] use max_length argument as varchar length --- sqlmodel/_compat.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sqlmodel/_compat.py b/sqlmodel/_compat.py index 072d2b0f58..0f0ab1b539 100644 --- a/sqlmodel/_compat.py +++ b/sqlmodel/_compat.py @@ -201,7 +201,9 @@ def get_field_metadata(field: Any) -> Any: for meta in field.metadata: if isinstance(meta, PydanticMetadata): return meta - return FakeMetadata() + fake = FakeMetadata() + fake.max_length = getattr(meta, "max_length", None) + return fake def post_init_field_info(field_info: FieldInfo) -> None: return None