Artifact creation does not work in 0.15.6 (tenant_id is null)
Description
Artifact creation hits an API error where the tenant_id is NULL. This also might be related to a similar issue with StartFlowRun().run() being used in another task that gives a similar error message. This is specifically 0.15.6 and up.
This minimal example:
from prefect.artifacts import create_markdown
import prefect
from prefect import task, Flow
@task
def foo(param):
create_markdown(f'Task {prefect.context["task_full_name"]}: {param}')
with Flow(
'test_artifacts',
) as flow:
foo('unmapped') # <-- this works
foo.map([1, 2, 3]) # <-- this doesn't
if __name__ == "__main__":
flow.register(project_name='test')
Yields
prefect.exceptions.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\'}]'}}}]
There is also a similar issue where using StartFlowRun().run() inside another task also yields
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\'}]'}}}])
StartFlowRun().run() seems to fail but create_flow_run.run() works.
Actually the version 0.15.5 is the one that broke it. I've put some debug logs here https://github.com/PrefectHQ/prefect/blob/5fee7a791d2448d9a7919722edb368c4ba905a19/src/prefect/client/client.py#L2155
From unmapped run (works):
{'mutation($input: create_task_run_artifact_input!)': {'create_task_run_artifact(input: $input)': {'id'}}}
{'input': {'task_run_id': '65f55244-948d-4e38-88c1-d6eb7cf82dba', 'kind': 'markdown', 'data': {'markdown': 'Task foo: unmapped'}, 'tenant_id': None}}
From mapped run (doesn't work):
{'mutation($input: create_task_run_artifact_input!)': {'create_task_run_artifact(input: $input)': {'id'}}}
{'input': {'task_run_id': '87ffe39e-39b1-4fb2-9e42-a92d653fb5af', 'kind': 'markdown', 'data': {'markdown': 'Task foo[0]: 1'}, 'tenant_id': None}}
Hi! Is this using Prefect Cloud or Server? If using Cloud, are you authenticating with an API key or authentication token?
I'm running it in locally deployed server + local agent - prefect server start + prefect agent local start --show-flow-logs
I stumble upon this issue as well. https://github.com/PrefectHQ/prefect/issues/5309 Any news on here?
Hey, thanks @nneuh07, looks like you found the bug already, thanks for that! https://github.com/PrefectHQ/prefect/issues/5309#issuecomment-1010318486
This could indicate a storage issue because the CLI registers the flow with script storage (and works with
.map()) whileflow.register()pickles the flow (and doesn't work with.map()).