Skip to content

Commit

Permalink
Fixup pydantic deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
wjdp committed Jul 30, 2023
1 parent 0b96d5b commit 034042f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/lumina/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DynamoExportMixin:
def ddict(self: BaseModelProtocol, **kwargs):
"""dict() export for DynamoDB, removes any Python-only fields, essentially
JSON but still in dict form"""
return jsonable_encoder(self.dict(**kwargs))
return jsonable_encoder(self.model_dump(**kwargs))


class BaseDynamoModel(BaseModel):
Expand Down Expand Up @@ -96,5 +96,7 @@ class SubmissionModel(BaseDynamoModel, DynamoExportMixin):

@property
def issue_id(self) -> int:
# TODO: Use this when we have Python 3.9
return int(self.sk.split("/")[-1])
try:
return int(self.sk.removeprefix(table.SK_SUBMISSION_PREFIX))
except ValueError as e:
raise ValueError(f"Invalid target_id: {self.sk}, cannot parse int") from e
2 changes: 1 addition & 1 deletion src/lumina/database/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def move_anonymous_submissions_to_member(
# Create a new submission using the member ID
new_member_submissions.append(
# Direct copy and change only the PK
put_submission(anonymous_submission.copy(update={"pk": member_id}))
put_submission(anonymous_submission.model_copy(update={"pk": member_id}))
)
# Delete the old submission
delete_response = get_member_table().delete_item(
Expand Down
2 changes: 1 addition & 1 deletion src/lumina/github/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def verify_webhook(signature: str, body: bytes) -> bool:


def update_issue_from_webhook(webhook: GitHubWebhook) -> None:
github_issue = GitHubIssueModel(**webhook.issue.dict())
github_issue = GitHubIssueModel(**webhook.issue.model_dump())
github_issue.state = get_state_from_issue(webhook.issue)
if not webhook.issue:
raise ValueError("Webhook does not contain an issue")
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/lumina/database/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _make_submission(id: int, **kwargs) -> SubmissionModel:
closed_at=None,
comments=0,
),
).copy(update=kwargs)
).model_copy(update=kwargs)


def test_put_member_submission():
Expand Down Expand Up @@ -189,7 +189,7 @@ def test_update_submission_github_issue():
to_close_at = dates.now()
operations.update_submission_github_issue(
101,
new_submission.github_issue.copy(
new_submission.github_issue.model_copy(
update={
"state": GitHubIssueState.CLOSED,
"comments": 5,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lumina/endpoints/test_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_success_self_first_call(
auth_fred_bloggs,
snapshot,
):
mock_get_member.return_value = MemberModel(**auth_fred_bloggs.dict())
mock_get_member.return_value = MemberModel(**auth_fred_bloggs.model_dump())
mock_get_member.return_value.email_verified_at = "2021-01-01T00:00:00"
response = client.get("/member/fred_bloggs")
assert response.status_code == HTTPStatus.OK, response.json()
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/lumina/endpoints/test_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ def test_success_not_authed(self):
# This mess needed as pydantic doesn't serialise UUID by default
# See https://github.com/samuelcolvin/pydantic/issues/1157
json={
**submission_request.dict(),
**submission_request.model_dump(),
"submitter": {
**submission_request.submitter.dict(),
**submission_request.submitter.model_dump(),
"id": str(submission_request.submitter.id),
},
},
Expand Down Expand Up @@ -311,7 +311,7 @@ def test_success_authed(self, auth_fred_bloggs):
)
response = client.post(
"/submissions/message",
json=submission_request.dict(),
json=submission_request.model_dump(),
)
assert response.status_code == HTTPStatus.OK
assert response.json() == {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lumina/github/test_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_issue_closed(self):
webhooks.handle_webhook(ISSUE_CLOSED_HOOK)
assert mock_update_issue.call_count == 1
assert mock_update_issue.call_args[0][1] == GitHubIssueModel(
**ISSUE_CLOSED_HOOK.issue.dict()
**ISSUE_CLOSED_HOOK.issue.model_dump()
)

def test_issue_completed(self):
Expand Down

0 comments on commit 034042f

Please sign in to comment.