Skip to content
12 changes: 10 additions & 2 deletions sqlmodel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ def get_config(name: str) -> Any:
# other future tools based on Pydantic can use.
new_cls.__config__.read_with_orm_mode = True

config_validate = get_config("validate")
if config_validate is True:
# If it was passed by kwargs, ensure it's also set in config
new_cls.__config__.validate = config_validate
for k, v in new_cls.__fields__.items():
col = get_column_from_field(v)
setattr(new_cls, k, col)

config_registry = get_config("registry")
if config_registry is not Undefined:
config_registry = cast(registry, config_registry)
Expand Down Expand Up @@ -501,8 +509,8 @@ def __init__(__pydantic_self__, **data: Any) -> None:
# Only raise errors if not a SQLModel model
if (
not getattr(__pydantic_self__.__config__, "table", False)
and validation_error
):
or getattr(__pydantic_self__.__config__, "validate", False)
) and validation_error:
raise validation_error
# Do not set values as in Pydantic, pass them through setattr, so SQLAlchemy
# can handle them
Expand Down