From 8f10485266424f8b1501bb6ed6226848f99dffd9 Mon Sep 17 00:00:00 2001 From: Martin Thorsen Ranang Date: Fri, 15 Nov 2024 10:35:11 +0100 Subject: [PATCH] Support upcoming changes in Pydantic version 2.10. Without this fix, any SQLModel-based model with `table=True` and a `Field` that sets `default_factory=...` will brake with the following error message: `ValueError: 'validated_data' must be provided if 'call_default_factory' is True.` --- sqlmodel/_compat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sqlmodel/_compat.py b/sqlmodel/_compat.py index 4e80cdc374..29149ea301 100644 --- a/sqlmodel/_compat.py +++ b/sqlmodel/_compat.py @@ -252,7 +252,8 @@ def sqlmodel_table_construct( elif name in values: fields_values[name] = values.pop(name) elif not field.is_required(): - defaults[name] = field.get_default(call_default_factory=True) + defaults[name] = field.get_default(call_default_factory=True, + validated_data=fields_values) if _fields_set is None: _fields_set = set(fields_values.keys()) fields_values.update(defaults)