Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor bug involving locally cached tasks and no schedule #1599

Merged
merged 1 commit into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ These changes are available in the [master branch](https://github.com/PrefectHQ/

### Fixes

- None
- Fix issue with running local Flow without a schedule containing cached tasks - [#1599](https://github.com/PrefectHQ/prefect/pull/1599)

### Deprecations

Expand Down
6 changes: 3 additions & 3 deletions src/prefect/core/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,6 @@ def _run_on_schedule(
task_states = kwargs.pop("task_states", {})
flow_state.result.update(task_states)

# set global caches that persist across runs
prefect.context.setdefault("caches", {})

# set context for this flow run
flow_run_context = kwargs.pop(
"context", {}
Expand Down Expand Up @@ -999,6 +996,9 @@ def run(
)
)

# set global caches that persist across runs
prefect.context.setdefault("caches", {})

if run_on_schedule is None:
run_on_schedule = cast(bool, prefect.config.flows.run_on_schedule)
if run_on_schedule is False:
Expand Down
15 changes: 15 additions & 0 deletions tests/core/test_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,21 @@ def store_y(y):

assert storage == dict(y=[1, 1, 3])

def test_flow_dot_run_without_schedule_can_run_cached_tasks(self):
# simulate fresh environment
if "caches" in prefect.context:
del prefect.context["caches"]

@task(cache_for=datetime.timedelta(minutes=1))
def noop():
pass

f = Flow("test-caches", tasks=[noop])
flow_state = f.run(run_on_schedule=False)

assert flow_state.is_successful()
assert flow_state.result[noop].result is None

def test_flow_dot_run_handles_mapped_cached_states(self):
class MockSchedule(prefect.schedules.Schedule):
call_count = 0
Expand Down