Anthony L
05/02/2022, 10:02 PMrandom
generates the same values between runs.
I'm using Prefect Cloud 1.0 and running a local agent (with Prefect 1.2.1 library installed).
Here's my flow:
import prefect
from prefect import task, Flow
from random import random
@task
def task1():
logger = prefect.context.get("logger")
random_val = random()
<http://logger.info|logger.info>(f"{random_val=}")
if random_val < 0.5:
raise Exception()
with Flow("random-bug-flow") as flow:
task1()
flow.register(project_name="ant-flows")
I manually scheduled a run of this flow in Prefect Cloud and I see the random value in the logs. However, when I schedule another run (and any run thereafter), it generates the same "random" value. Is this expected?Kevin Kho
05/02/2022, 10:04 PMAnthony L
05/02/2022, 10:05 PMKevin Kho
05/02/2022, 10:06 PMAnthony L
05/02/2022, 10:08 PMKevin Kho
05/02/2022, 10:10 PMAnthony L
05/02/2022, 10:11 PMAnna Geller
05/02/2022, 11:56 PMflow.register()
it will, by default, use script storage and should then dynamically generate the number
I tried that and I'm getting different numbers at each run:
from prefect import task, Flow
from random import random
@task(log_stdout=True)
def rand_float():
random_val = random()
print(f"{random_val=}")
with Flow("random_nr_flow") as flow:
rand_float()
0.26524578590511527
(packaging-prefect-flows) ā community-1-0 prefect run --name random_nr_flow --watch
Looking up flow metadata... Done
Creating run for flow 'random_nr_flow'... Done
āāā Name: pink-numbat
āāā UUID: a2d3da01-2be6-47cc-b2f9-39b517ea320d
āāā Labels: ['annas-MBP.fritz.box']
āāā Parameters: {}
āāā Context: {}
āāā URL: <https://cloud.prefect.io/anna-prefect/flow-run/a2d3da01-2be6-47cc-b2f9-39b517ea320d>
Watching flow run execution...
āāā 01:56:45 | INFO | Entered state <Scheduled>: Flow run scheduled.
āāā 01:56:54 | INFO | Entered state <Submitted>: Submitted for execution
āāā 01:56:55 | INFO | Submitted for execution: PID: 38051
āāā 01:56:55 | INFO | Entered state <Running>: Running flow.
āāā 01:56:55 | INFO | Beginning Flow run for 'random_nr_flow'
āāā 01:56:56 | INFO | Task 'rand_float': Starting task run...
āāā 01:56:57 | INFO | random_val=0.26524578590511527
āāā 01:56:57 | INFO | Task 'rand_float': Finished task run for task with final state: 'Success'
āāā 01:56:57 | INFO | Flow run SUCCESS: all reference tasks succeeded
āāā 01:56:57 | INFO | Entered state <Success>: All reference tasks succeeded.
Flow run succeeded!
Anthony L
05/03/2022, 3:28 AMflow.register(..)
fixes the issue on my end. Thanks Anna!Kevin Kho
05/03/2022, 3:35 AM