Skip to content

Commit 78bbdd3

Browse files
committed
fix
1 parent f21fae2 commit 78bbdd3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

nowcasting_datamodel/read/read.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from datetime import datetime, timedelta, timezone
99
from typing import List, Optional
1010

11-
from sqlalchemy import desc
11+
from sqlalchemy import desc, text
1212
from sqlalchemy.orm import contains_eager, joinedload
1313
from sqlalchemy.orm.session import Session
1414

@@ -307,13 +307,16 @@ def get_latest_forecast_for_gsps(
307307
query=query, start_target_time=start_target_time, historic=historic
308308
)
309309

310-
from sqlalchemy import text
311-
312310
if forecast_horizon_minutes is not None:
313311
assert historic is False, Exception(
314312
"Loading a forecast horizon only works on non latest data."
315313
)
316-
query = query.join(ForecastValueSQL).filter(
314+
315+
# need to join the ForecastValueSQL table
316+
if start_target_time is None:
317+
query = query.join(ForecastValueSQL)
318+
319+
query = query.filter(
317320
ForecastValueSQL.target_time - ForecastValueSQL.created_utc
318321
>= text(f"interval '{forecast_horizon_minutes} minute'")
319322
)

0 commit comments

Comments
 (0)