fix(aurora): fixed an issue with json encoding
This commit is contained in:
parent
1990b97518
commit
db477c4744
2 changed files with 9 additions and 3 deletions
|
@ -9,14 +9,20 @@ class AuroraBaseModel(BaseModel):
|
|||
model_config = ConfigDict(ignored_types=(Red,), arbitrary_types_allowed=True)
|
||||
bot: Red
|
||||
|
||||
def dump(self) -> dict:
|
||||
return self.model_dump(exclude={"bot"})
|
||||
|
||||
def to_json(self, indent: int | None = None, file: Any | None = None, **kwargs):
|
||||
from ..utilities.json import dump, dumps # pylint: disable=cyclic-import
|
||||
return dump(self.model_dump(exclude={"bot"}), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot"}), indent=indent, **kwargs)
|
||||
return dump(self.dump(), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot"}), indent=indent, **kwargs)
|
||||
|
||||
class AuroraGuildModel(AuroraBaseModel):
|
||||
"""Subclass of AuroraBaseModel that includes a guild_id attribute, and a modified to_json() method to match."""
|
||||
guild_id: int
|
||||
|
||||
def dump(self) -> dict:
|
||||
return self.model_dump(exclude={"bot", "guild_id"})
|
||||
|
||||
def to_json(self, indent: int | None = None, file: Any | None = None, **kwargs):
|
||||
from ..utilities.json import dump, dumps # pylint: disable=cyclic-import
|
||||
return dump(self.model_dump(exclude={"bot", "guild_id"}), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot", "guild_id"}), indent=indent, **kwargs)
|
||||
return dump(self.dump(), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot", "guild_id"}), indent=indent, **kwargs)
|
||||
|
|
|
@ -13,7 +13,7 @@ class JSONEncoder(json.JSONEncoder):
|
|||
if isinstance(o, timedelta):
|
||||
return str(o)
|
||||
if isinstance(o, AuroraBaseModel):
|
||||
return o.to_json()
|
||||
return o.dump()
|
||||
if isinstance(o, Red):
|
||||
return None
|
||||
return super().default(o)
|
||||
|
|
Loading…
Reference in a new issue