Skip to content

Commit

Permalink
Adds test
Browse files Browse the repository at this point in the history
  • Loading branch information
desertaxle committed Jul 19, 2024
1 parent 3ecac8e commit a62d9b2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/test-projects/flows/uses_block.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import uuid

from prefect import flow
from prefect.blocks.system import Secret

block_name = f"foo-{uuid.uuid4()}"
Secret(value="bar").save("foo")

my_secret = Secret.load("foo")


@flow
async def uses_block():
return my_secret.get()
34 changes: 33 additions & 1 deletion tests/test_flow_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pydantic
import pytest

from prefect import Flow, flow, task
from prefect import Flow, __development_base_path__, flow, task
from prefect._internal.compatibility.experimental import ExperimentalFeature
from prefect.client.orchestration import PrefectClient, SyncPrefectClient
from prefect.client.schemas.filters import FlowFilter, FlowRunFilter
Expand All @@ -37,6 +37,7 @@
from prefect.logging import get_run_logger
from prefect.server.schemas.core import FlowRun as ServerFlowRun
from prefect.utilities.callables import get_call_parameters
from prefect.utilities.filesystem import tmpchdir


@flow
Expand Down Expand Up @@ -1730,3 +1731,34 @@ def g(required: str, model: TheModel = {"x": [1, 2, 3]}): # type: ignore
yield i

assert [i for i in g("hello")] == ["hello", 1, 2, 3]


class TestLoadFlowAndFlowRun:
async def test_load_flow_from_script_with_module_level_sync_compatible_call(
self, prefect_client: PrefectClient, tmp_path
):
"""
This test ensures that when a worker or runner loads a flow from a script, and
that script contains a module-level call to a sync-compatible function, the sync
compatible function is correctly runs as sync and does not prevent the flow from
being loaded.
Regression test for https://github.com/PrefectHQ/prefect/issues/14625
"""
flow_id = await prefect_client.create_flow_from_name(flow_name="uses_block")
deployment_id = await prefect_client.create_deployment(
flow_id=flow_id,
name="test-load-flow-from-script-with-module-level-sync-compatible-call",
path=str(__development_base_path__ / "tests" / "test-projects" / "flows"),
entrypoint="uses_block.py:uses_block",
)
api_flow_run = await prefect_client.create_flow_run_from_deployment(
deployment_id=deployment_id
)

with tmpchdir(tmp_path):
flow_run, flow = load_flow_and_flow_run(api_flow_run.id)

assert flow_run.id == api_flow_run.id

assert await flow() == "bar"

0 comments on commit a62d9b2

Please sign in to comment.