Skip to content

Commit dbd8551

Browse files
committed
♻️ Tweak sqlmodel/_compat.py for compatibility with Pydantic v3
1 parent b23a457 commit dbd8551

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

sqlmodel/_compat.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,14 @@ def set_config_value(
103103
model.model_config[parameter] = value # type: ignore[literal-required]
104104

105105
def get_model_fields(model: InstanceOrType[BaseModel]) -> Dict[str, "FieldInfo"]:
106-
return model.model_fields # type: ignore[arg-type]
106+
# TODO: refactor the usage of this function to always pass the class
107+
# not the instance, and then remove this extra check
108+
# this is for compatibility with Pydantic v3
109+
if isinstance(model, type):
110+
use_model = model
111+
else:
112+
use_model = model.__class__
113+
return use_model.model_fields
107114

108115
def get_fields_set(
109116
object: InstanceOrType["SQLModel"],

0 commit comments

Comments
 (0)