https://prefect.io logo
Title
e

Elliot Oram

11/18/2020, 6:17 PM
Hi all, Is there a way to ask prefect server what the code in a particular flow is? Currently if I register a flow and then register it again with the exact same code it will increment the version number even though the flow is identical. I can write a system to store a local hashed version of the file and then compare before I re-register, but I wanted to check if you guys had a better solution before I do that! Thanks 🙂
z

Zanie

11/18/2020, 6:20 PM
Hi @Elliot Oram! We don’t want Server to know what your code is because it violates our hybrid model in which we are blissfully ignorant of your intellectual property. However, you can pass an
idempotency_key
to
flow.register
which will not create a new version if the key is the same and we also added a
flow.serialized_hash()
function that will compute a deterministic hash of the flow data so you can use that as the key. There’s a blurb in the docs at https://docs.prefect.io/orchestration/tutorial/first.html#register-flow-with-the-prefect-api
Note that the serialized flow doesn’t actually contain your code as well though so the hash generated from that may not change when some logic within your tasks changes (this is a little complicated and could probably use some more docs)
d

Dave

11/18/2020, 7:19 PM
I personally couldn't get it working properly 😞 So I ended up with simply saving a hash value of the registered script.
z

Zanie

11/18/2020, 8:05 PM
I found another bug with it today 😞
d

Dave

11/18/2020, 8:11 PM
No worries, when I have some time then I would for sure contribute on Github, just busy migrating stuff to Prefect from Airflow 😛refect-duck: Let me know if you need some assistance Elliot, but I suggest just saving a hash value of the file you just registered then you can quickly check if you already registered that specific file with the hash.
z

Zanie

11/18/2020, 9:30 PM
The bug I found is being addressed in https://github.com/PrefectHQ/prefect/pull/3682 — but hashing based on actual code changes is a bit trickier!
d

Dave

11/18/2020, 9:59 PM
Ah cool, yes that I can agree on.
e

Elliot Oram

11/19/2020, 8:47 AM
Thanks both, I'll go down the local hash route for now 👍