Skip to content

Commit

Permalink
Remove autoescape from jinja - allow to use special chars in variable…
Browse files Browse the repository at this point in the history
…s. (#2193)
  • Loading branch information
jzalucki authored Jan 6, 2025
1 parent 5021b74 commit e319d37
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion soda/core/soda/common/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def resolve_or_missing(self, key):


def create_os_environment():
environment = SandboxedEnvironment(variable_start_string="${", variable_end_string="}", autoescape=True)
environment = SandboxedEnvironment(variable_start_string="${", variable_end_string="}")
environment.context_class = OsContext
return environment

Expand Down
27 changes: 27 additions & 0 deletions soda/core/tests/data_source/test_user_defined_metric_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,33 @@ def test_user_defined_data_source_query_metric_check_with_variable(data_source_f
assert 1068 < avg_surface < 1069


def test_user_defined_data_source_query_metric_check_with_variable_special_chars(
data_source_fixture: DataSourceFixture,
):
table_name = data_source_fixture.ensure_test_table(customers_test_table)

qualified_table_name = data_source_fixture.data_source.qualified_table_name(table_name)

scan = data_source_fixture.create_test_scan()
scan.add_variables({"cst_size": ">= -5"})
scan.add_sodacl_yaml_str(
f"""
checks:
- avg_surface between 1068 and 1069:
avg_surface query: |
SELECT AVG(cst_size * distance) as avg_surface
FROM {qualified_table_name} WHERE cst_size ${{cst_size}} OR cst_size IS NULL
"""
)
scan.execute()

scan.assert_all_checks_pass()

avg_surface = scan._checks[0].check_value
assert isinstance(avg_surface, float)
assert 1068 < avg_surface < 1069


def test_user_defined_data_source_query_metric_with_sql_file(data_source_fixture: DataSourceFixture):
fd, path = tempfile.mkstemp()
table_name = data_source_fixture.ensure_test_table(customers_test_table)
Expand Down

0 comments on commit e319d37

Please sign in to comment.