This is an automated email from the ASF dual-hosted git repository. rusackas pushed a commit to branch revert-32731-feat/return-none-where_in-jinja-filter in repository https://gitbox.apache.org/repos/asf/superset.git
commit 426b70921d1b6214937cdab7b3018691e0bd1415 Author: Evan Rusackas <[email protected]> AuthorDate: Tue Mar 18 13:19:16 2025 -0600 Revert "feat(where_in): Support returning None if filter_values return None (…" This reverts commit 850801f510e4aa2636b18d0c234ad2bd94c43443. --- superset/jinja_context.py | 17 +++-------------- tests/unit_tests/jinja_context_test.py | 13 ------------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/superset/jinja_context.py b/superset/jinja_context.py index a4d8e6d6a4..f500881ba4 100644 --- a/superset/jinja_context.py +++ b/superset/jinja_context.py @@ -519,12 +519,7 @@ class WhereInMacro: # pylint: disable=too-few-public-methods def __init__(self, dialect: Dialect): self.dialect = dialect - def __call__( - self, - values: list[Any], - mark: Optional[str] = None, - default_to_none: bool = False, - ) -> str | None: + def __call__(self, values: list[Any], mark: Optional[str] = None) -> str: """ Given a list of values, build a parenthesis list suitable for an IN expression. @@ -533,10 +528,6 @@ class WhereInMacro: # pylint: disable=too-few-public-methods >>> where_in([1, "Joe's", 3]) (1, 'Joe''s', 3) - The `default_to_none` parameter is used to determine the return value when the - list of values is empty: - - If `default_to_none` is `False` (default), the return value is (). - - If `default_to_none` is `True`, the return value is `None`. """ binds = [bindparam(f"value_{i}", value) for i, value in enumerate(values)] string_representations = [ @@ -548,11 +539,9 @@ class WhereInMacro: # pylint: disable=too-few-public-methods for bind in binds ] joined_values = ", ".join(string_representations) - result = ( - f"({joined_values})" if (joined_values or not default_to_none) else None - ) + result = f"({joined_values})" - if mark and result: + if mark: result += ( "\n-- WARNING: the `mark` parameter was removed from the `where_in` " "macro for security reasons\n" diff --git a/tests/unit_tests/jinja_context_test.py b/tests/unit_tests/jinja_context_test.py index be6e5fb55e..d2ec9c8345 100644 --- a/tests/unit_tests/jinja_context_test.py +++ b/tests/unit_tests/jinja_context_test.py @@ -416,19 +416,6 @@ def test_where_in() -> None: assert where_in(["O'Malley's"]) == "('O''Malley''s')" -def test_where_in_empty_list() -> None: - """ - Test the ``where_in`` Jinja2 filter when it receives an - empty list. - """ - where_in = WhereInMacro(mysql.dialect()) - - # By default, the filter should return empty parenthesis (as a string) - assert where_in([]) == "()" - # With the default_to_none parameter set to True, it should return None - assert where_in([], default_to_none=True) is None - - def test_dataset_macro(mocker: MockerFixture) -> None: """ Test the ``dataset_macro`` macro.
