Skip to content

Commit

Permalink
[BUGFIX] Stop overwriting template with description (#10826)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-hoffman authored Jan 8, 2025
1 parent 5adca6c commit 996c72d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
11 changes: 1 addition & 10 deletions great_expectations/render/renderer_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,6 @@ def _validate_and_set_renderer_attrs(cls, values: dict) -> dict:
].expectation_config
values["expectation_type"] = expectation_configuration.type
values["kwargs"] = expectation_configuration.kwargs
# description is the template_str override
if expectation_configuration.description:
values["template_str"] = expectation_configuration.description
raw_configuration: ExpectationConfiguration = (
expectation_configuration.get_raw_configuration()
)
Expand Down Expand Up @@ -543,13 +540,7 @@ def _get_row_condition_string(row_condition_str: str) -> str:

@validator("template_str")
def _set_template_str(cls, v: str, values: dict) -> str:
if values.get("configuration") and values["configuration"].description:
# description always overrides other template_strs
v = values["configuration"].description
elif values.get("result") and values["result"].expectation_config.description:
# description always overrides other template_strs
v = values["result"].expectation_config.description
elif values.get("_row_condition"):
if values.get("_row_condition"):
row_condition_str: str = RendererConfiguration._get_row_condition_string(
row_condition_str=values["_row_condition"]
)
Expand Down
54 changes: 54 additions & 0 deletions tests/expectations/test_expectation_atomic_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2995,3 +2995,57 @@ def test_unexpected_rows_expectation_atomic_diagnostic_observed_value(

# assert
assert res["value"]["template"] == expected_template_string


@pytest.mark.unit
def test_unexpected_rows_expectation_atomic_diagnostic_observed_value_when_description_present(
get_diagnostic_rendered_content,
):
"""Fixes regression where description overwrote the template"""

x = {
"expectation_config": ExpectationConfiguration(
type="unexpected_rows_expectation",
kwargs={"description": "my description", "unexpected_rows_query": "valid query"},
description="plz ignore me",
),
"result": {"observed_value": 123},
}

res = get_diagnostic_rendered_content(x).to_json_dict()

assert res["value"]["template"] == "$observed_value unexpected rows"


@pytest.mark.unit
def test_atomic_prescriptive_summary_with_description(
get_prescriptive_rendered_content,
):
description = "I should overwite"
update_dict = {
"type": "expect_column_distinct_values_to_be_in_set",
"description": description,
"kwargs": {
"column": "my_column",
"value_set": [1, 2, 3],
},
}
rendered_content = get_prescriptive_rendered_content(update_dict)

res = rendered_content.to_json_dict()
pprint(res)
assert res == {
"name": "atomic.prescriptive.summary",
"value": {
"params": {
"column": {"schema": {"type": "string"}, "value": "my_column"},
"v__0": {"schema": {"type": "number"}, "value": 1},
"v__1": {"schema": {"type": "number"}, "value": 2},
"v__2": {"schema": {"type": "number"}, "value": 3},
"value_set": {"schema": {"type": "array"}, "value": [1, 2, 3]},
},
"schema": {"type": "com.superconductive.rendered.string"},
"template": description,
},
"value_type": "StringValueType",
}

0 comments on commit 996c72d

Please sign in to comment.