fix(aurora): use AuroraBaseModels for the JSONEncoder class instead of just pydantic ones to prevent issues with other data types
Some checks failed
Actions / Build Documentation (MkDocs) (pull_request) Successful in 32s
Actions / Lint Code (Ruff & Pylint) (pull_request) Failing after 48s

This commit is contained in:
Seaswimmer 2024-05-04 15:37:07 -04:00
parent ca7c0d8d7c
commit 2dfc9d9824
Signed by: cswimr
GPG key ID: 5D671B5D03D65A7F
2 changed files with 6 additions and 3 deletions

View file

@ -5,7 +5,10 @@ from typing import Dict, List, Optional
from pydantic import BaseModel from pydantic import BaseModel
class Moderation(BaseModel):
class AuroraBaseModel(BaseModel):
"""Base class for all models in Aurora."""
class Moderation(AuroraBaseModel):
moderation_id: int moderation_id: int
guild_id: int guild_id: int
timestamp: datetime timestamp: datetime

View file

@ -1,7 +1,7 @@
import json import json
from datetime import datetime, timedelta from datetime import datetime, timedelta
from pydantic import BaseModel from aurora.models import AuroraBaseModel
class JSONEncoder(json.JSONEncoder): class JSONEncoder(json.JSONEncoder):
@ -10,7 +10,7 @@ class JSONEncoder(json.JSONEncoder):
return int(o.timestamp()) return int(o.timestamp())
if isinstance(o, timedelta): if isinstance(o, timedelta):
return str(o) return str(o)
if isinstance(o, BaseModel): if isinstance(o, AuroraBaseModel):
return o.model_dump() return o.model_dump()
return super().default(o) return super().default(o)