Skip to content

Commit

Permalink
Fix dashboard link unique bug (#487)
Browse files Browse the repository at this point in the history
The frontend will send `"dashboard_link": ""` (empty string) but it
should be converted to `None` instead. Otherwise tournaments quickly
have non-unique endpoints.
  • Loading branch information
evroon authored Feb 17, 2024
1 parent 6899980 commit 41c664e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion backend/bracket/models/db/tournament.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pydantic import Field

from bracket.models.db.shared import BaseModelORM
from bracket.utils.pydantic import EmptyStrToNone


class Tournament(BaseModelORM):
Expand All @@ -23,7 +24,7 @@ class TournamentUpdateBody(BaseModelORM):
start_time: datetime_utc
name: str
dashboard_public: bool
dashboard_endpoint: str | None = None
dashboard_endpoint: EmptyStrToNone | str = None
players_can_be_in_multiple_teams: bool
auto_assign_courts: bool
duration_minutes: int = Field(..., ge=1)
Expand Down
13 changes: 13 additions & 0 deletions backend/bracket/utils/pydantic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import Annotated

from pydantic import PlainValidator


def accept_none_and_empty_str(value: str | None) -> None:
if value is None or value == "":
return None

raise ValueError("Not an empty str or None")


EmptyStrToNone = Annotated[None, PlainValidator(accept_none_and_empty_str)]

0 comments on commit 41c664e

Please sign in to comment.