How to check whether a flow run was triggered ad-hoc or from a deployment?

Check if the deployment ID is set in the flow run context, if it’s None then it’s an ad-hoc run

from prefect import flow, context


@flow
def myflow():
    x = context.get_run_context()
    print(x.flow_run.deployment_id)