Skip to content

Commit

Permalink
Raise an exception when filters' value isn't a list. (#2576)
Browse files Browse the repository at this point in the history
* Add an exeception when filters' value isn't a list

* Make the exception more specific

Signed-off-by: Nelson Chen <asd3431090@gmail.com>

* add an unit test for value_in

Signed-off-by: Nelson Chen <asd3431090@gmail.com>

* lint

Signed-off-by: Kevin Su <pingsutw@apache.org>

---------

Signed-off-by: Nelson Chen <asd3431090@gmail.com>
Signed-off-by: Kevin Su <pingsutw@apache.org>
Co-authored-by: Kevin Su <pingsutw@apache.org>
  • Loading branch information
2 people authored and Future-Outlier committed Aug 6, 2024
1 parent 3a689e1 commit c14d4bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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

0 comments on commit c14d4bf

Please sign in to comment.