cuddly-jelly-27016
04/18/2025, 8:09 PMCache constructor's policies kwarg is typed Optional[Union[List[CachePolicy], CachePolicy]], so it should accept a list of policies.
But it throws an error. This minimal snippet:
from flytekit.core.cache import Cache, CachePolicy, VersionParameters
class TestCachePolicy(CachePolicy):
def get_version(self, salt: str, params: VersionParameters) -> str:
return "test"
cache_obj = Cache(policies=[TestCachePolicy(), TestCachePolicy()])
Produces the following error:
[file]: <module>
cache_obj = Cache(
<string>:8: in __init__
???
[cache.py path]: in __post_init__
if self.version is None and not self._policies:
E AttributeError: 'Cache' object has no attribute '_policies'. Did you mean: 'policies'?
I think the constructor just needs to add a case to set self._policies if policies is a list: https://github.com/flyteorg/flytekit/blob/26db7a3f48589d49b927fd4c251974a83530868d/flytekit/core/cache.py#L74
### Expected behavior
The provided code snippet does not throw an exception.
### Additional context to reproduce
No response
### Screenshots
No response
### Are you sure this issue hasn't been raised already?
• Yes
### Have you read the Code of Conduct?
• Yes
flyteorg/flytecuddly-jelly-27016
05/03/2025, 1:02 PM