From b7f3c6630de2d42dae6e5b54c01e666e608d2416 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Tue, 19 Mar 2024 11:55:22 +0100 Subject: [PATCH] Ensure `contents_active` return 0 instead of None When there is no content. --- client/src/api/schema/schema.ts | 9 +++------ lib/galaxy/managers/history_contents.py | 6 +++--- lib/galaxy/schema/schema.py | 12 ++++++------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/client/src/api/schema/schema.ts b/client/src/api/schema/schema.ts index 738685693143..d55c9b73f17c 100644 --- a/client/src/api/schema/schema.ts +++ b/client/src/api/schema/schema.ts @@ -6531,21 +6531,18 @@ export interface components { /** * Active * @description Number of active datasets. - * @default 0 */ - active?: number | null; + active: number; /** * Deleted * @description Number of deleted datasets. - * @default 0 */ - deleted?: number | null; + deleted: number; /** * Hidden * @description Number of hidden datasets. - * @default 0 */ - hidden?: number | null; + hidden: number; }; /** HistoryContentBulkOperationPayload */ HistoryContentBulkOperationPayload: { diff --git a/lib/galaxy/managers/history_contents.py b/lib/galaxy/managers/history_contents.py index 0a4a09f08f00..a07953918738 100644 --- a/lib/galaxy/managers/history_contents.py +++ b/lib/galaxy/managers/history_contents.py @@ -183,9 +183,9 @@ def active_counts(self, history): hdca_select = self._active_counts_statement(model.HistoryDatasetCollectionAssociation, history.id) subquery = hda_select.union_all(hdca_select).subquery() statement = select( - cast(func.sum(subquery.c.deleted), Integer).label("deleted"), - cast(func.sum(subquery.c.hidden), Integer).label("hidden"), - cast(func.sum(subquery.c.active), Integer).label("active"), + cast(func.coalesce(func.sum(subquery.c.deleted), 0), Integer).label("deleted"), + cast(func.coalesce(func.sum(subquery.c.hidden), 0), Integer).label("hidden"), + cast(func.coalesce(func.sum(subquery.c.active), 0), Integer).label("active"), ) returned = self.app.model.context.execute(statement).one() return dict(returned._mapping) diff --git a/lib/galaxy/schema/schema.py b/lib/galaxy/schema/schema.py index 3418d169d806..8bc60b8f9dc8 100644 --- a/lib/galaxy/schema/schema.py +++ b/lib/galaxy/schema/schema.py @@ -1254,18 +1254,18 @@ class HistorySummary(HistoryBase, WithModelClass): class HistoryActiveContentCounts(Model): """Contains the number of active, deleted or hidden items in a History.""" - active: Optional[int] = Field( - default=0, + active: int = Field( + ..., title="Active", description="Number of active datasets.", ) - hidden: Optional[int] = Field( - default=0, + hidden: int = Field( + ..., title="Hidden", description="Number of hidden datasets.", ) - deleted: Optional[int] = Field( - default=0, + deleted: int = Field( + ..., title="Deleted", description="Number of deleted datasets.", )