Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove autoescape from jinja - allow to use special chars in variables. #2193

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading