Skip to content

Commit a1cbca8

Browse files
author
Allen M. Foster
committed
allow for union which wraps the actual pydantic classes
1 parent d53ee74 commit a1cbca8

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

mapcat/database/json.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
See: https://github.com/fastapi/sqlmodel/pull/1324 - this can be removed at some point.
55
"""
66

7+
import typing
8+
79
from sqlalchemy.types import JSON, TypeDecorator
810

911

@@ -23,4 +25,8 @@ def process_bind_param(self, value, dialect):
2325
def process_result_value(self, value, dialect):
2426
if value is None:
2527
return None
26-
return self.pydantic_class.model_validate(value)
28+
cls = self.pydantic_class
29+
args = typing.get_args(cls)
30+
if args:
31+
cls = next(a for a in args if a is not type(None))
32+
return cls.model_validate(value)

0 commit comments

Comments
 (0)