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

Raise an exception when filters' value isn't a list. #2576

Merged
merged 7 commits into from
Aug 5, 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
2 changes: 2 additions & 0 deletions flytekit/models/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def __init__(self, key, values):
:param Text key: The name of the field to compare against
:param list[Text] values: A list of textual values to compare.
"""
if not isinstance(values, list):
raise TypeError(f"values must be a list. but got {type(values)}")
super(SetFilter, self).__init__(key, ";".join(values))

@classmethod
Expand Down
6 changes: 5 additions & 1 deletion tests/flytekit/unit/models/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flytekit.models import filters

import pytest

def test_eq_filter():
assert filters.Equal("key", "value").to_flyte_idl() == "eq(key,value)"
Expand Down Expand Up @@ -28,6 +28,10 @@ def test_lte_filter():
def test_value_in_filter():
assert filters.ValueIn("key", ["1", "2", "3"]).to_flyte_idl() == "value_in(key,1;2;3)"

def test_invalid_value_in_filter():
with pytest.raises(TypeError, match=r"values must be a list. but got .*"):
filters.ValueIn("key", "1")


def test_contains_filter():
assert filters.Contains("key", ["1", "2", "3"]).to_flyte_idl() == "contains(key,1;2;3)"
Expand Down
Loading