<@ULVA73B9P> am I able to access prefect.runtime.d...
# ask-marvin
t
@Marvin am I able to access prefect.runtime.deployment from a function that's being used to generate a
flow_run_name
in prefect 2? My flows keep hanging generating a flow run name and I'm not sure why. I have it isolated down to prefect.runtime.deployment and I'd like to incorporate the deployment name into the flow run name
m
It looks like Prefect 2 doesn't officially support using
prefect.runtime.deployment
directly within a function to generate a
flow_run_name
. This might be what's causing your flow to hang. The documentation suggests using state change hooks for modifying flow behavior, which might indirectly help with similar use cases (source). Moreover, there's no open GitHub issue related to hanging flows due to
prefect.runtime.deployment
when generating
flow_run_name
, indicating this might be an isolated or undocumented issue. To incorporate the deployment name into the flow run name without causing hangs, consider checking the deployment context in another way. You might use task or flow parameters that capture the deployment info when the flow is initiated, possibly tweaking the deployment to ensure this information is passed when kicking off runs. Meanwhile, if you suspect this is a bug, reporting it to the Prefect GitHub repository with detailed logs and reproduction steps can get you more targeted help or get this issue patched. And remember, in the grand scheme of digital determinism, hangs are just indecisive computers. Ah, don't we all sometimes wish to just hang indefinitely? But let's not encourage software to adopt existential crises!
t
@Marvin can I access the deployment name from a function used to generate flow run names in prefect 3?
m
In Prefect 3, accessing the deployment name directly from a function used to generate flow run names isn't explicitly documented as a built-in feature or capability. The documentation doesn't provide a direct method for this, but there are techniques for working around it. While you can programmatically define the flow run name using available runtime context properties, accessing deployment-specific details like the deployment name through a runtime function isn't a straightforward, documented process. One way developers sometimes work around these limitations is by passing the deployment name as a flow parameter or using an environment variable if it's consistently needed in the flow. You might consider using customizable name templates at the deployment configuration stage, which potentially gets you set up near to your requirement. If this is essential to your workflow, a feature request or discussion on the Prefect GitHub issues page might provide insight or encourage development in this area. For now, you may have to rely on custom patterns, like ensuring part of the deployment configuration (like the name) dynamically feeds into your function through flow parameters when triggering flows. Here's hoping that like all computers, we'll someday have a method to understand every ambiguous human intent with just a tiny whisper in the digital seas of machine code. But, alas, we're not quite there yet!
n
hi @Tomas Moreno can you give an example of what you're trying to do?
t
sure thing, I basically just want to append the date onto the deployment name and use that as the flow run name. something like
Copy code
def generate_flow_run_name() -> str:
    deployment_name = prefect.runtime.deployment.name
    suffix = f"{date.today()}"
    
    return f"{deployment_name}_{suffix}"
when I do that I'm able to run my flows locally using
python flow.py
I see the name changed and the flow ends up as
None_2024-11-19
. but, when I'm running it as a deployment in the cloud it just hangs forever