Hi all! I have a question about using the idempot...
# ask-community
j
Hi all! I have a question about using the idempotency key when registering a new flow. I am using flow.serialized_hash() as it is described in the documentation. However, there are some global variables that are used in my flow, and when they changed the flow serialized hash doesn’t, so my flow is not registered if I use the idempotency key. Anyone had the same problem and how did you manage to solve it? Thank you very much!
đź‘€ 1
I mean, the global variables are used in the tasks, not inside the flow definition. Like this:
Copy code
MSG = "hello"
@task
def t1():
    logger = prefect.context.get("logger")
    <http://logger.info|logger.info>(MSG)

with Flow("myflow") as f:
    f1()

flow.register(project_name="...", idempotency_key=flow.serialized_hash())
k
Hi @jcozar, what do you think of doing something like
flow.register(project_name="...", idempotency_key=flow.serialized_hash() + MSG)
?
j
Hi @Kevin Kho, you’re totally right! Reading the source code:
Copy code
Note that this will not always detect code changes since the task code is not included in the serialized flow sent to the server.
In my case, the global vars are used by the tasks, and therefore the hash does not change even if I modify the global var. However, based on your solution, I think I will get the hash string from the hole python file, because I only declare prefect resources in it (infrastructure is deployed independently). Thanks!