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

fix: also re-attach a detached source to the TimedBelief object #745

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 6 additions & 4 deletions flexmeasures/data/models/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,15 @@ def __init__(
source: tb.DBBeliefSource,
**kwargs,
):
# get a Sensor instance attached to the database session (input sensor is detached)
# get a Sensor instance attached to the database session (if input sensor is detached)
# check out Issue #683 for more details
inspection_obj = inspect(sensor, raiseerr=False)
if (
inspection_obj and inspection_obj.detached
): # fetch Sensor only when it is detached
if inspection_obj and inspection_obj.detached:
sensor = Sensor.query.get(sensor.id)
# do the same for DataSource
inspection_obj = inspect(source, raiseerr=False)
if inspection_obj and inspection_obj.detached:
source = DataSource.query.get(source.id)

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