fix UnboundLocalError on modified_statistic_ids in compile_statistics (#116795)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Patrick Decat 2024-05-04 20:16:58 +02:00 committed by GitHub
parent f143ed9eeb
commit ac12d2a463
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -485,6 +485,12 @@ def compile_statistics(instance: Recorder, start: datetime, fire_events: bool) -
The actual calculation is delegated to the platforms.
"""
# Define modified_statistic_ids outside of the "with" statement as
# _compile_statistics may raise and be trapped by
# filter_unique_constraint_integrity_error which would make
# modified_statistic_ids unbound.
modified_statistic_ids: set[str] | None = None
# Return if we already have 5-minute statistics for the requested period
with session_scope(
session=instance.get_session(),