File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
nowcasting_datamodel/read Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 8
8
from datetime import datetime , timedelta , timezone
9
9
from typing import List , Optional
10
10
11
- from sqlalchemy import desc
11
+ from sqlalchemy import desc , text
12
12
from sqlalchemy .orm import contains_eager , joinedload
13
13
from sqlalchemy .orm .session import Session
14
14
@@ -307,13 +307,16 @@ def get_latest_forecast_for_gsps(
307
307
query = query , start_target_time = start_target_time , historic = historic
308
308
)
309
309
310
- from sqlalchemy import text
311
-
312
310
if forecast_horizon_minutes is not None :
313
311
assert historic is False , Exception (
314
312
"Loading a forecast horizon only works on non latest data."
315
313
)
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 (
317
320
ForecastValueSQL .target_time - ForecastValueSQL .created_utc
318
321
>= text (f"interval '{ forecast_horizon_minutes } minute'" )
319
322
)
You can’t perform that action at this time.
0 commit comments