This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-release.git
The following commit(s) were added to refs/heads/main by this push:
new d3065f2 Correct the validation for some API models
d3065f2 is described below
commit d3065f250a00cab33f67e57e4d83a5422d8a4260
Author: Sean B. Palmer <[email protected]>
AuthorDate: Mon Jul 28 19:09:23 2025 +0100
Correct the validation for some API models
---
atr/blueprints/api/api.py | 3 +--
atr/models/api.py | 18 ++++++++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/atr/blueprints/api/api.py b/atr/blueprints/api/api.py
index 5ec71c4..6032cbb 100644
--- a/atr/blueprints/api/api.py
+++ b/atr/blueprints/api/api.py
@@ -664,9 +664,8 @@ async def releases_project(project: str, query_args:
models.api.ReleasesProjectQ
).model_dump(), 200
-# TODO: If we validate as sql.Release, quart_schema silently corrupts
latest_revision_number to None
-# @quart_schema.validate_response(models.api.ReleasesVersionResults, 200)
@api.BLUEPRINT.route("/releases/version/<project>/<version>")
+@quart_schema.validate_response(models.api.ReleasesVersionResults, 200)
async def releases_version(project: str, version: str) -> DictResponse:
"""Return a single release by project and version."""
_simple_check(project, version)
diff --git a/atr/models/api.py b/atr/models/api.py
index f876170..3a565d8 100644
--- a/atr/models/api.py
+++ b/atr/models/api.py
@@ -58,6 +58,11 @@ class ChecksListResults(schema.Strict):
checks_revision: str = schema.Field(..., **example("00005"))
current_phase: sql.ReleasePhase = schema.Field(...,
**example(sql.ReleasePhase.RELEASE_CANDIDATE))
+ @pydantic.field_validator("current_phase", mode="before")
+ @classmethod
+ def current_phase_to_enum(cls, v):
+ return sql.ReleasePhase(v) if isinstance(v, str) else v
+
class ChecksOngoingResults(schema.Strict):
endpoint: Literal["/checks/ongoing"] = schema.Field(alias="endpoint")
@@ -264,6 +269,19 @@ class ReleasesVersionResults(schema.Strict):
endpoint: Literal["/releases/version"] = schema.Field(alias="endpoint")
release: sql.Release
+ @pydantic.field_validator("release", mode="before")
+ @classmethod
+ def _preserve_latest_revision_number(cls, v):
+ if isinstance(v, dict):
+ data = dict(v)
+ lrn = data.pop("latest_revision_number", None)
+ allowed = {k: data[k] for k in data if k in
sql.Release.model_fields}
+ obj = sql.Release(**allowed)
+ if lrn is not None:
+ setattr(obj, "_latest_revision_number", lrn)
+ return obj
+ return v
+
class ReleasesRevisionsResults(schema.Strict):
endpoint: Literal["/releases/revisions"] = schema.Field(alias="endpoint")
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]