From 6fc1efd3e079a7d73c1238f9dda55a4550f9f5cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Thu, 7 Jul 2022 23:17:57 +0200 Subject: [PATCH 1/2] do not fail the sensor attribute when building an entity address fails. Do warn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolas Höning --- .pre-commit-config.yaml | 4 ++-- flexmeasures/data/models/time_series.py | 14 ++++++++++++-- flexmeasures/utils/entity_address_utils.py | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 454f57d2a..2188b6c12 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,13 +4,13 @@ repos: hooks: - id: flake8 name: flake8 (code linting) - language_version: python3.8 + language_version: python3.9 - repo: https://github.com/psf/black rev: 22.3.0 # New version tags can be found here: https://github.com/psf/black/tags hooks: - id: black name: black (code formatting) - language_version: python3.8 + language_version: python3.9 - repo: local hooks: - id: mypy diff --git a/flexmeasures/data/models/time_series.py b/flexmeasures/data/models/time_series.py index 03700c34a..a79947fc4 100644 --- a/flexmeasures/data/models/time_series.py +++ b/flexmeasures/data/models/time_series.py @@ -1,6 +1,7 @@ from typing import Any, List, Dict, Optional, Union, Type, Tuple from datetime import datetime as datetime_type, timedelta import json +from flask import current_app import pandas as pd from sqlalchemy.ext.declarative import declared_attr @@ -24,7 +25,10 @@ collect_time_series_data, aggregate_values, ) -from flexmeasures.utils.entity_address_utils import build_entity_address +from flexmeasures.utils.entity_address_utils import ( + EntityAddressException, + build_entity_address, +) from flexmeasures.utils.unit_utils import is_energy_unit, is_power_unit from flexmeasures.data.models.annotations import ( Annotation, @@ -112,7 +116,13 @@ def __acl__(self): @property def entity_address(self) -> str: - return build_entity_address(dict(sensor_id=self.id), "sensor") + try: + return build_entity_address(dict(sensor_id=self.id), "sensor") + except EntityAddressException as eae: + current_app.logger.warn( + f"Problems generating entity address for sensor {self}: {eae}" + ) + return "no entity address available" @property def location(self) -> Optional[Tuple[float, float]]: diff --git a/flexmeasures/utils/entity_address_utils.py b/flexmeasures/utils/entity_address_utils.py index e507e0144..985bf973c 100644 --- a/flexmeasures/utils/entity_address_utils.py +++ b/flexmeasures/utils/entity_address_utils.py @@ -325,7 +325,7 @@ def build_ea_scheme_and_naming_authority( "FLEXMEASURES_HOSTS_AND_AUTH_START", {} )[config_var_domain_key] else: - raise Exception( + raise EntityAddressException( f"Could not find out when authority for {config_var_domain_key} started. Is FLEXMEASURES_HOSTS_AND_AUTH_START configured for it?" ) regex = r"^\d{4}-\d{2}$" From c5516d5023ac19e1c077812ac42eaa0ac5d5a563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Thu, 7 Jul 2022 23:21:26 +0200 Subject: [PATCH 2/2] changelog entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolas Höning --- documentation/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/documentation/changelog.rst b/documentation/changelog.rst index 731e6b5d7..637f19908 100644 --- a/documentation/changelog.rst +++ b/documentation/changelog.rst @@ -12,11 +12,13 @@ New features Bugfixes ----------- +* Do not fail asset page if entity addresses cannot be built [see `PR #457 `_] Infrastructure / Support ---------------------- * Allow access tokens to be passed as env vars as well [see `PR #443 `_] + v0.10.1 | June XX, 2022 ===========================