<#6420 [BUG] flytekit: Cache object "policies" kwa...
# flyte-github
c
#6420 [BUG] flytekit: Cache object "policies" kwarg typing accepts a list, but errors if provided a list Issue created by ddl-ryan-connor ### Describe the bug The
Cache
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:
Copy code
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:
Copy code
[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/flyte