Hi everyone :smile: We've recently upgraded to the...
# ask-community
s
Hi everyone 😄 We've recently upgraded to the 0.15.6 Prefect version (both server and flows), but if we use start a flow by another flow by using the
StartFlowRun.run()
this error is shown:
Copy code
Error during execution of task: ClientError([{'message': '[{\'extensions\': {\'path\': \'$.selectionSet.insert_task_run_artifact.args.objects\', \'code\': \'constraint-violation\'}, \'message\': \'Not-NULL violation. null value in column "tenant_id" violates not-null constraint\'}]', 'locations': [{'line': 2, 'column': 5}], 'path': ['create_task_run_artifact'], 'extensions': {'code': 'INTERNAL_SERVER_ERROR', 'exception': {'message': '[{\'extensions\': {\'path\': \'$.selectionSet.insert_task_run_artifact.args.objects\', \'code\': \'constraint-violation\'}, \'message\': \'Not-NULL violation. null value in column "tenant_id" violates not-null constraint\'}]'}}}])
We are migrating from
0.14.22
version, we are using
server
as the backend in local Can anybody help?
a
Hi @Stefano Cascavilla when it comes to changes to Server, I’m only aware of an additional --expose flag that you need to add when starting server since 0.15.5: https://docs.prefect.io/orchestration/server/deploy-local
But when it comes to StartFlowRun, you definitely need to make sure that your child flow is registered before you can call it from the parent flow. Perhaps you can try to reregister both child and parent flows, and check if the error reappears?
s
Thanks! I've tried again registering them but still get the same issue
a
I’m not that familiar with Server, but by looking at the error, perhaps you need to create a tenant?
Copy code
prefect server create-tenant
s
Already tried this solution, but with no luck 😞 I created a tenant, I started the flows from that custom new tenant, but still got the same issue
a
I think I know what’s the issue. You’re probably calling
StartFlowRun
from another task. Have a look at this: https://prefect-community.slack.com/archives/CL09KU1K7/p1632911162461300?thread_ts=1632754964.329100&cid=CL09KU1K7
s
Actually I'm calling the StartFlowRun.run() inside another task. Would we call it with mapped params if we need? (without calling it into another task?)
@Anna Geller My concern is: how can I map a StartFlowRun.run() call?
I've just tested the flow with 0.15.4 version and it worked. I suspect one of the breaking changes in the 0.15.5 could impact our flows. I've tried starting the server with
--expose
flag, but received the same error
a
@Stefano Cascavilla if all your child flows are within the same project, this is how you could map over flows:
Copy code
from prefect import Flow, unmapped
from prefect.tasks.prefect import create_flow_run
from prefect.executors import LocalDaskExecutor


with Flow("MasterFlow_Mapped", executor=LocalDaskExecutor()) as flow:
    mapped_flows = create_flow_run.map(
        flow_name=["flow_name_1", "flow_name_2", "flow_name_3"],
        project_name=unmapped("Flow_of_Flows"),
    )

if __name__ == "__main__":
    flow.run()
I tested this and it works - they are ran in parallel. But I’m using the create_flow_run task rather than StartFlowRun. Could you give it a try?
@Stefano Cascavilla alternatively, this is how it could be implemented using `StartFlowRun`:
Copy code
from prefect import Flow, unmapped, task
from prefect.tasks.prefect import StartFlowRun
from prefect.executors import LocalDaskExecutor
from uuid import uuid4


@task
def run_subflow(flow_name):
    StartFlowRun(flow_name=flow_name, project_name="Flow_of_Flows", wait=True).run(
        idempotency_key=str(uuid4())
    )


with Flow("MasterFlow_Mapped", executor=LocalDaskExecutor()) as flow:
    mapped_flows = run_subflow.map(
        flow_name=["flow_name_1", "flow_name_2", "flow_name_3"]
    )

if __name__ == "__main__":
    flow.run()
s
Hi @Anna Geller, thanks for the answer. This was the same situation we already have. I've tried adding the
idempotency_key
param to the
run
invocation, but received the same error.
a
@Stefano Cascavilla Did you try both versions with
StartFlowRun
and
create_flow_run
above and none of that worked? Can you share your flow code so that we can reproduce the issue?
s
Just tried with the
create_flow_run
along with
wait_for_flow_run
and worked fine! Thank you so much! 😄
❤️ 1
upvote 2
a
@Anna Geller would you suggest using
create_flow_run
instead of
StartFlowRun
as a best practice?
a
@ale, at Prefect, we don’t want to give opinionated recommendations 🙂 But overall,
StartFlowRun
was initially built to manage subflows but it did it in a way which combines multiple actions in one task. The new tasks
create_flow_run
,
wait_for_flow_run
and
get_task_run_result
separate the concerns, and are much easier to combine with other tasks - you can read more here.
🎉 1
a
Hey @Anna Geller thanks for sharing! We’ll definitely look into these new tasks 🙌
👍 1
k
I opened an issue for this here