From: Christian Heller Date: Fri, 21 Jun 2024 16:26:04 +0000 (+0200) Subject: Avoid confusing Day.by_id_or_create by always translating dating string first, so... X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/static/process_descriptions?a=commitdiff_plain;h=ef4dfff9ff3002c11ccfef4190999a5e4e513606;p=plomtask Avoid confusing Day.by_id_or_create by always translating dating string first, so a look-up for "today" or so does not ignore the date equivalents. --- diff --git a/plomtask/days.py b/plomtask/days.py index 92e44b2..7e6a5cc 100644 --- a/plomtask/days.py +++ b/plomtask/days.py @@ -34,6 +34,13 @@ class Day(BaseModel[str]): day.todos = Todo.by_date(db_conn, day.id_) return day + @classmethod + def by_id_or_create(cls, db_conn: DatabaseConnection, id_: str | None + ) -> Day: + """Extend BaseModel.by_id to ensure date name translation.""" + assert isinstance(id_, str) + return super().by_id_or_create(db_conn, valid_date(id_)) + @classmethod def by_id(cls, db_conn: DatabaseConnection, id_: str) -> Day: """Extend BaseModel.by_id checking for new/lost .todos."""