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

add function name to prefect-docker cache key #15262

Merged
merged 3 commits into from
Sep 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ def cacheable(func):
@wraps(func)
def wrapper(*args, **kwargs):
if ignore_cache := kwargs.pop("ignore_cache", False):
logger.debug("Ignoring `@cacheable` decorator for build_docker_image.")
logger.debug(f"Ignoring `@cacheable` decorator for {func.__name__}.")
key = (
func.__name__,
tuple(_make_hashable(arg) for arg in args),
tuple((k, _make_hashable(v)) for k, v in sorted(kwargs.items())),
)
Expand Down
25 changes: 25 additions & 0 deletions src/integrations/prefect-docker/tests/deployments/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,28 @@ def test_uncached_push_docker_image(self, mock_docker_client):
assert mock_docker_client.login.call_count == 3
expected_push_calls = 1 + len(additional_tags)
assert mock_docker_client.api.push.call_count == expected_push_calls * 3

def test_avoids_aggressive_caching(self, mock_docker_client):
"""this is a regression test for https://github.com/PrefectHQ/prefect/issues/15258
where all decorated functions were sharing a cache, so dict(image=..., tag=...) passed to
build_docker_image and push_docker_image would hit the cache for push_docker_image,
even though the function was different and should not have been cached.

here we test that the caches are distinct for each decorated function.
"""
image_name = "registry/repo"
tag = "latest"

build_docker_image(
image_name=image_name,
tag=tag,
)

# Push the image (this should not hit the cache)
push_docker_image(
image_name=image_name,
tag=tag,
)

mock_docker_client.api.build.assert_called_once()
mock_docker_client.api.push.assert_called_once()
Loading