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

Deduce cache version iff cache_version is not set #2734

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eapolinario
Copy link
Collaborator

Tracking issue

flyteorg/flyte#770

Why are the changes needed?

We should decrease the burden to use a cache in the case of python tasks.

What changes were proposed in this pull request?

This PR calls inspect.getsource passing the task function as an argument, which loads the actual source code of the function and use that to use generate a string to represent the cache version.

Notice that any change to the function (including adding/removing a parameter, changing the docstring, rearranging/reindenting some code) is going to produce a new value. In other words, the function can be moved around in a file, but its contents cannot change, otherwise a new value is going to be generated.

How was this patch tested?

Unit tests and local executions.

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

@@ -378,6 +381,21 @@ def wrapper(fn: Callable[P, Any]) -> PythonFunctionTask[T]:
return wrapper


def _deduce_cache_version(fn: Callable[P, Any]) -> str:
Copy link
Member

@thomasjpfan thomasjpfan Sep 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the task uses an imported function, any updates to the imported function would not be captured by inspect.getsource:

from utils import helper

@task(cache=True)
def my_task(x: int):
    x = my_helper(x)

I think this is okay as long as we documented the behavior and tell users what to do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. I think it's okay too. Could we also update the docstring for cache_version here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants