From 05157c9ce4408eec08cf9455c466c44b80043f84 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 19 Feb 2023 15:24:49 -0600 Subject: [PATCH] fix refactoring error --- homeassistant/components/recorder/statistics.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/recorder/statistics.py b/homeassistant/components/recorder/statistics.py index d52b659c427..c6e32e06888 100644 --- a/homeassistant/components/recorder/statistics.py +++ b/homeassistant/components/recorder/statistics.py @@ -2002,10 +2002,13 @@ def _statistics_at_time( stmt = lambda_stmt(lambda: columns) most_recent_statistic_ids = ( - # https://github.com/sqlalchemy/sqlalchemy/issues/9189 - # pylint: disable-next=not-callable lambda_stmt( - lambda: select(func.max(table.id).label("max_start_ts"), table.metadata_id) + lambda: select( + # https://github.com/sqlalchemy/sqlalchemy/issues/9189 + # pylint: disable-next=not-callable + func.max(table.start_ts).label("max_start_ts"), + table.metadata_id, + ) ) .filter(table.start_ts < start_time_ts) .filter(table.metadata_id.in_(metadata_ids)) @@ -2018,6 +2021,7 @@ def _statistics_at_time( table.start_ts == most_recent_statistic_ids.c.max_start_ts and table.metadata_id == most_recent_statistic_ids.c.metadata_id, ) + return cast(Sequence[Row], execute_stmt_lambda_element(session, stmt))