Skip to content

Commit

Permalink
fix: fix TypeError: Object of type 'ModelMetaclass' is not JSON seria…
Browse files Browse the repository at this point in the history
…lizable
  • Loading branch information
Ljzd-PRO committed Dec 1, 2023
1 parent 60fef40 commit 0a4520a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ktoolbox/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Type, Any, List, Generic, TypeVar, Union
import json
from typing import Type, Any, List, Generic, TypeVar, Union, Dict

from pydantic import BaseModel

Expand All @@ -9,6 +10,11 @@
_T = TypeVar("_T")


def _dump_type(obj: Dict[str, Any], *args, **kwargs):
obj["type"] = str(obj["type"])
return json.dumps(obj, *args, **kwargs)


class BaseKToolBoxData(BaseModel):
"""
Base class for all KToolBox data models.
Expand All @@ -21,6 +27,9 @@ def __init__(self, **data: Any):
version: str = __version__
type: Union[Type["BaseKToolBoxData"], str] = None

class Config(BaseModel.Config):
json_dumps = _dump_type


class SearchResult(BaseKToolBoxData, Generic[_T]):
"""Cli search result"""
Expand Down

0 comments on commit 0a4520a

Please sign in to comment.