Skip to content

Commit

Permalink
Merge bb7bdd4 into 726cd32
Browse files Browse the repository at this point in the history
  • Loading branch information
victorgarcia98 committed Jun 9, 2023
2 parents 726cd32 + bb7bdd4 commit 66f08b6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions flexmeasures/data/models/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from sqlalchemy.ext.mutable import MutableDict
from sqlalchemy.orm import Query, Session
from sqlalchemy.schema import UniqueConstraint
from sqlalchemy import inspect
import timely_beliefs as tb
from timely_beliefs.beliefs.probabilistic_utils import get_median_belief
import timely_beliefs.utils as tb_utils
Expand Down Expand Up @@ -584,6 +585,14 @@ def __init__(
source: tb.DBBeliefSource,
**kwargs,
):
# get a Sensor instance attached to the database session (input sensor is detached)
# check out Issue #683 for more details
inspection_obj = inspect(sensor, raiseerr=False)
if inspection_obj:
# fetch Sensor only when it is detached
if inspection_obj.detached:
sensor = Sensor.query.get(sensor.id)

tb.TimedBeliefDBMixin.__init__(self, sensor, source, **kwargs)
tb_utils.remove_class_init_kwargs(tb.TimedBeliefDBMixin, kwargs)
db.Model.__init__(self, **kwargs)
Expand Down

0 comments on commit 66f08b6

Please sign in to comment.