Skip to content

Commit b0cdfa7

Browse files
Debug Search Result Seralization (#64)
1 parent bb57964 commit b0cdfa7

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

dsms/knowledge/search.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import TYPE_CHECKING, Generator, List, Union
44

55
import oyaml as yaml
6-
from pydantic import BaseModel, Field
6+
from pydantic import BaseModel, Field, model_serializer
77

88
from dsms.core.session import Session
99

@@ -41,6 +41,21 @@ def __repr__(self):
4141
"""Pretty print the KItemSearchResult"""
4242
return str(self)
4343

44+
@model_serializer()
45+
def serialze_results(self):
46+
"""
47+
Custom model serializer.
48+
49+
Needs to be added since the `model_dump` was only
50+
serializing the compact model, not the full representation.
51+
"""
52+
return {
53+
key: (
54+
value.model_dump() if isinstance(value, BaseModel) else value
55+
)
56+
for key, value in self
57+
}
58+
4459

4560
class SearchResult(BaseModel):
4661
"""DSMS search result"""

0 commit comments

Comments
 (0)