From 149d7eea0019ff29719947cba9e9f5551d444371 Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Thu, 18 Apr 2024 10:23:09 -0700 Subject: [PATCH] fix(sql_parse): Support Jinja format() filter when extracting latest[_sub]_partition (#28117) (cherry picked from commit 2f11f6616794228fc3633da4571d32ec598dd9b7) --- superset/sql_parse.py | 2 +- tests/unit_tests/sql_parse_tests.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/superset/sql_parse.py b/superset/sql_parse.py index d2e20f9cbae..ed463a40e68 100644 --- a/superset/sql_parse.py +++ b/superset/sql_parse.py @@ -1104,7 +1104,7 @@ def extract_tables_from_jinja_sql(sql: str, database: Database) -> set[Table]: Table( *[ remove_quotes(part.strip()) - for part in node.args[0].value.split(".")[::-1] + for part in node.args[0].as_const().split(".")[::-1] if len(node.args) == 1 ] ) diff --git a/tests/unit_tests/sql_parse_tests.py b/tests/unit_tests/sql_parse_tests.py index bbb19fd8033..1aa92cb90dd 100644 --- a/tests/unit_tests/sql_parse_tests.py +++ b/tests/unit_tests/sql_parse_tests.py @@ -1895,6 +1895,7 @@ SELECT * FROM t""" [ "latest_partition('foo.bar')", "latest_partition(' foo.bar ')", # Non-atypical user error which works + "latest_partition('foo.%s'|format('bar'))", "latest_sub_partition('foo.bar', baz='qux')", ], )