Skip to content

Commit

Permalink
datetime.utcnow is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavberi committed Apr 4, 2024
1 parent 775c3f7 commit 1fc9bfa
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
from typing import List, Any

from datetime import datetime
from pytz import timezone


def create_utc_time():
return datetime.now(timezone("UTC"))


# for handling mongo ObjectIds
Expand Down Expand Up @@ -41,7 +46,7 @@ class Mails(BaseModel):
to_recipients: List[EmailStr] = Field(...)
cc_recipients: List[EmailStr] = Field([])

sent_time: datetime = Field(default_factory=datetime.utcnow, frozen=True)
sent_time: datetime = Field(default_factory=create_utc_time, frozen=True)

@field_validator("to_recipients")
@classmethod
Expand Down Expand Up @@ -88,10 +93,10 @@ class CCRecruitment(BaseModel):
why_this_position: str = Field()
why_cc: str = Field()
ideas: str = Field()
other_bodies: str = Field()
other_bodies: str | None = None
good_fit: str = Field()

sent_time: datetime = Field(default_factory=datetime.utcnow, frozen=True)
sent_time: datetime = Field(default_factory=create_utc_time, frozen=True)

# TODO[pydantic]: The following keys were removed: `json_encoders`.
# Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information.
Expand Down

0 comments on commit 1fc9bfa

Please sign in to comment.