Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not fail the sensor attribute when building an entity address #457

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions documentation/changelog.rst
Expand Up @@ -12,11 +12,13 @@ New features

Bugfixes
-----------
* Do not fail asset page if entity addresses cannot be built [see `PR #457 <http://www.github.com/FlexMeasures/flexmeasures/pull/457>`_]

Infrastructure / Support
----------------------
* Allow access tokens to be passed as env vars as well [see `PR #443 <http://www.github.com/FlexMeasures/flexmeasures/pull/443>`_]


v0.10.1 | June XX, 2022
===========================

Expand Down
14 changes: 12 additions & 2 deletions 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
Expand All @@ -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,
Expand Down Expand Up @@ -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]]:
Expand Down
2 changes: 1 addition & 1 deletion flexmeasures/utils/entity_address_utils.py
Expand Up @@ -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}$"
Expand Down