Skip to content

Commit

Permalink
Fix Pydantic deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavberi committed Sep 14, 2024
1 parent 0d63b04 commit fcc0bc7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
6 changes: 0 additions & 6 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,9 @@ def validate_unique_cc(cls, value):
)
return value

# TODO[pydantic]: The following keys were removed: `json_encoders`.
# Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. # noqa: E501
model_config = ConfigDict(
populate_by_name=True,
arbitrary_types_allowed=True,
json_encoders={ObjectId: str},
extra="forbid",
str_strip_whitespace=True,
validate_assignment=True,
Expand Down Expand Up @@ -103,12 +100,9 @@ class CCRecruitment(BaseModel):

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. # noqa: E501
model_config = ConfigDict(
populate_by_name=True,
arbitrary_types_allowed=True,
json_encoders={ObjectId: str},
extra="forbid",
str_strip_whitespace=True,
validate_assignment=True,
Expand Down
6 changes: 3 additions & 3 deletions mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ def sendMail(
# send_mail(mail_input["subject"], mail_input["body"],
# mail_input["to_recipients"], mail_input["cc_recipients"]):

# created_sample = Mails.parse_obj(
# created_sample = Mails.model_validate(
# db.mails.find_one({"_id": 0}, {"_id": 0}))
# else:
# # add to database
# created_id = db.mails.insert_one(mail_input).inserted_id
#
# # query from database
# created_sample = Mails.parse_obj(
# created_sample = Mails.model_validate(
# db.mails.find_one({"_id": created_id}, {"_id": 0}))
#
# return MailReturnType.from_pydantic(created_sample)
Expand All @@ -86,7 +86,7 @@ def ccApply(ccRecruitmentInput: CCRecruitmentInput, info: Info) -> bool:

# add to database
created_id = ccdb.insert_one(cc_recruitment_input).inserted_id
created_sample = CCRecruitment.parse_obj(
created_sample = CCRecruitment.model_validate(
ccdb.find_one({"_id": created_id})
)

Expand Down
2 changes: 1 addition & 1 deletion queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def ccApplications(info: Info) -> List[CCRecruitmentType]:

results = ccdb.find()
applications = [
CCRecruitmentType.from_pydantic(CCRecruitment.parse_obj(result))
CCRecruitmentType.from_pydantic(CCRecruitment.model_validate(result))
for result in results
]

Expand Down

0 comments on commit fcc0bc7

Please sign in to comment.