Skip to content

Commit

Permalink
fix(ingest/looker): Don't fail on unknown liquid filters (datahub-pro…
Browse files Browse the repository at this point in the history
  • Loading branch information
treff7es authored and sleeperdeep committed Dec 17, 2024
1 parent 1eb4819 commit be1fa55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from liquid import Environment
from liquid.ast import Node
from liquid.context import Context
from liquid.filter import string_filter
from liquid.parse import expect, get_parser
from liquid.stream import TokenStream
from liquid.tag import Tag
Expand Down Expand Up @@ -81,12 +82,18 @@ def parse(self, stream: TokenStream) -> Node:
custom_tags = [ConditionTag]


@string_filter
def sql_quote_filter(variable: str) -> str:
return f"'{variable}'"


@lru_cache(maxsize=1)
def _create_env() -> Environment:
env: Environment = Environment()
env: Environment = Environment(strict_filters=False)
# register tag. One time activity
for custom_tag in custom_tags:
env.add_tag(custom_tag)
env.add_filter("sql_quote", sql_quote_filter)
return env


Expand Down
6 changes: 3 additions & 3 deletions metadata-ingestion/tests/integration/lookml/test_lookml.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ def test_view_to_view_lineage_and_liquid_template(pytestconfig, tmp_path, mock_t

@freeze_time(FROZEN_TIME)
def test_special_liquid_variables():
text: str = """
text: str = """{% assign source_table_variable = "source_table" | sql_quote | non_existing_filter_where_it_should_not_fail %}
SELECT
employee_id,
employee_name,
Expand All @@ -903,7 +903,7 @@ def test_special_liquid_variables():
'default_table' as source
{% endif %},
employee_income
FROM source_table
FROM {{ source_table_variable }}
"""
input_liquid_variable: dict = {}

Expand Down Expand Up @@ -958,7 +958,7 @@ def test_special_liquid_variables():
expected_text: str = (
"\n SELECT\n employee_id,\n employee_name,\n \n "
"prod_core.data.r_metric_summary_v2\n ,\n employee_income\n FROM "
"source_table\n "
"'source_table'\n "
)
assert actual_text == expected_text

Expand Down

0 comments on commit be1fa55

Please sign in to comment.