Skip to content

Race Condition Bug in xdg/predict_tryolabs Code #321

@symbioquine

Description

@symbioquine

Describe the bug

Concerning the predict_tryolabs branch of run_forecast...

if ts is None:
start_date = pd.Timestamp.now().strftime("%Y-%m-%d")
start_time = pd.Timestamp.now().round(freq="h")

# set start and end time, if no time is given use current time
if ts is None:
  start_date = pd.Timestamp.now().strftime("%Y-%m-%d")
  start_time = pd.Timestamp.now().round(freq="h")

The problem is that if this code runs close to midnight, the start_date and start_time variables can end up set a day apart. The subsequent code then runs the forecast for start_date + 2 days which may actually be only + 1 day from start_time - so the final filtered result will end up only containing a total of 1 days data instead of the desired 2 days worth.

To Reproduce

I haven't reproduced this, but if one wanted to demonstrate it, they could put a breakpoint on L84 and leave the interpreter paused until the time has (been) changed.

Expected behavior

Only get "now" once and derive the start_date and start_time variables from that.

# set start and end time, if no time is given use current time
if ts is None:
  now = pd.Timestamp.now()
  start_date = now.strftime("%Y-%m-%d")
  start_time = now.round(freq="h")

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcontributions-welcomeGood issue for open-source contribution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions