Skip to content

Commit 837b29d

Browse files
committed
Fix datetime serialization in config.py with UTC timezone and ISO format
1 parent 95b38f5 commit 837b29d

File tree

2 files changed

+1006
-997
lines changed

2 files changed

+1006
-997
lines changed

mcp_email_server/config.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pathlib import Path
66

77
import tomli_w
8-
from pydantic import BaseModel, Field, model_validator
8+
from pydantic import BaseModel, ConfigDict, Field, model_validator, field_serializer
99
from pydantic_settings import (
1010
BaseSettings,
1111
PydanticBaseSettingsSource,
@@ -33,6 +33,11 @@ def masked(self) -> EmailServer:
3333

3434

3535
class AccountAttributes(BaseModel):
36+
model_config = ConfigDict(
37+
json_encoders={
38+
datetime.datetime: lambda v: v.isoformat()
39+
}
40+
)
3641
account_name: str
3742
description: str = ""
3843
created_at: datetime.datetime = Field(default_factory=datetime.datetime.now)
@@ -59,6 +64,10 @@ def __eq__(self, other: object) -> bool:
5964
exclude={"created_at", "updated_at"}
6065
)
6166

67+
@field_serializer('created_at', 'updated_at')
68+
def serialize_datetime(self, v: datetime.datetime) -> str:
69+
return v.isoformat()
70+
6271
def masked(self) -> AccountAttributes:
6372
return self.model_copy()
6473

0 commit comments

Comments
 (0)