From c5aa734cad3d4a8a1f01d113fff05198218e7879 Mon Sep 17 00:00:00 2001 From: stuppie Date: Thu, 27 Aug 2026 17:46:17 -0600 Subject: Leaderboard id & name optional; set by validators --- generalresearch/models/thl/leaderboard.py | 17 +++++++++++------ pyproject.toml | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/generalresearch/models/thl/leaderboard.py b/generalresearch/models/thl/leaderboard.py index 399a906..bc55034 100644 --- a/generalresearch/models/thl/leaderboard.py +++ b/generalresearch/models/thl/leaderboard.py @@ -6,6 +6,7 @@ from datetime import datetime, timedelta, timezone from enum import Enum from typing import Literal from uuid import UUID, uuid3 +from zoneinfo import ZoneInfo import pandas as pd from pydantic import ( @@ -17,7 +18,6 @@ from pydantic import ( field_validator, model_validator, ) -from zoneinfo import ZoneInfo from generalresearch.models.custom_types import AwareDatetimeISO, UUIDStr from generalresearch.models.legacy.api_status import StatusResponse @@ -78,14 +78,19 @@ class Leaderboard(BaseModel): weekly, and monthly leaderboard. """ - id: UUIDStr = Field( + # Note: id and name get auto-generated by the model_validators, but the fields need + # to be optional with a default or the model can't be inited. + # todo: these should really be computed_fields instead + id: UUIDStr | None = Field( description="Unique ID for this leaderboard", examples=["845b0074ad533df580ebb9c80cc3bce1"], + default=None, ) - name: str = Field( + name: str | None = Field( description="Descriptive name for the leaderboard based on the board_code", examples=["Number of Completes"], + default=None, ) board_code: LeaderboardCode = Field( @@ -266,9 +271,9 @@ class Leaderboard(BaseModel): .to_pydatetime() .replace(tzinfo=self.timezone) ) - assert ( - period_start_local == self.period_start_local - ), f"invalid period_start_local {self.period_start_local}. The period starts at {period_start_local}" + assert period_start_local == self.period_start_local, ( + f"invalid period_start_local {self.period_start_local}. The period starts at {period_start_local}" + ) if self.period_end_local is not None: assert self.period_end_local == period_end_local, "invalid period" else: diff --git a/pyproject.toml b/pyproject.toml index fd55201..2d1d246 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "generalresearch" -version = "3.4.2" +version = "3.4.3" description = "Python Utilities for General Research" readme = "README.md" requires-python = ">=3.10" -- cgit v1.2.3