https://prefect.io logo
#prefect-server
Title
# prefect-server
f

fblaze f

12/31/2020, 5:40 PM
Hi! Whenever I rerun a flow, it reuses values from the previous run for the parameters declared globally. How should I handle this?
#!/usr/bin/python3
from datetime import datetime
from prefect import task, Flow, Parameter, context, case
from prefect.utilities.debug import is_serializable
logger = context.get("logger")
timestamp = datetime.now().strftime("%Y-%m-%dT%H-%M-%S")
@task
def print_timestamp():
<http://logger.info|logger.info>(timestamp)
with Flow("Test") as flow:
    
print_timestamp()
serializable = is_serializable(flow)
if serializable:
    
flow.register(project_name="Default",
                  
idempotency_key=flow.serialized_hash())
flow.run()
Attached screenshot from two runs. As you could see, the value of the global parameter
timestamp
hasn't changed
d

Dylan

12/31/2020, 5:45 PM
Hi @fblaze f! Since you’re creating that timestamp at Flow build time (i.e. as part of the definition outside of a Task), that value won’t be re-created when the Flow is run. If instead you create the timestamp inside of a Task, it should behave as you expect
👍 1
For example
Copy code
@task
def create_timestamp():
  return datetime.now().strftime("%Y-%m-%dT%H-%M-%S")

@task
def print_timestamp(timestamp):
   <http://logger.info|logger.info>(timestamp)
 
with Flow("test") as flow:
  ts = generate_timestamp()
  print_timestamp(ts)
Task execution is what’s deferred for runtime
Let me know if this helps 😄
f

fblaze f

12/31/2020, 5:53 PM
Thank you. That helps!
d

Dylan

12/31/2020, 5:56 PM
Great! marvin
2 Views