From ffc57e720910feeb6167af943ee18388e77c6717 Mon Sep 17 00:00:00 2001 From: rdimaio Date: Wed, 13 Mar 2024 12:19:02 +0100 Subject: [PATCH] Typing: Fix SQLA query and type hints in get_evaluation_backlog; #6550 --- lib/rucio/core/rule.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/rucio/core/rule.py b/lib/rucio/core/rule.py index 75e8d4bff8..9d6054596b 100644 --- a/lib/rucio/core/rule.py +++ b/lib/rucio/core/rule.py @@ -22,9 +22,9 @@ from os import path from re import match from string import Template -from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Type, TypeVar +from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Type, TypeVar, Union -from dogpile.cache.api import NO_VALUE +from dogpile.cache.api import NO_VALUE, NoValue from sqlalchemy import select, update from sqlalchemy.exc import IntegrityError, StatementError from sqlalchemy.exc import NoResultFound # https://pydoc.dev/sqlalchemy/latest/sqlalchemy.exc.NoResultFound.html @@ -2414,7 +2414,7 @@ def examine_rule(rule_id: str, *, session: "Session") -> dict[str, Any]: @transactional_session -def get_evaluation_backlog(expiration_time: int = 600, *, session: "Session") -> tuple[int, datetime]: +def get_evaluation_backlog(expiration_time: int = 600, *, session: "Session") -> Union[NoValue, tuple[int, datetime]]: """ Counts the number of entries in the rule evaluation backlog. (Number of files to be evaluated) @@ -2422,14 +2422,16 @@ def get_evaluation_backlog(expiration_time: int = 600, *, session: "Session") -> :returns: Tuple (Count, Datetime of oldest entry) """ - cached_backlog = REGION.get('rule_evaluation_backlog', expiration_time=expiration_time) + cached_backlog: Union[NoValue, tuple[int, datetime]] = REGION.get('rule_evaluation_backlog', expiration_time=expiration_time) if cached_backlog is NO_VALUE: - stmt = select(func.count(models.UpdatedDID.created_at), func.min(models.UpdatedDID.created_at)) - result = session.execute(stmt).scalars().one() + stmt = select( + func.count(models.UpdatedDID.created_at), + func.min(models.UpdatedDID.created_at) + ) + result = session.execute(stmt).one()._tuple() REGION.set('rule_evaluation_backlog', result) return result - else: - return cached_backlog # type: ignore + return cached_backlog @transactional_session