Skip to content

Commit

Permalink
[BUGFIX] V1 Validator shouldn't mutate user's result format dict (#10496
Browse files Browse the repository at this point in the history
)
  • Loading branch information
joshua-stauffer authored Oct 9, 2024
1 parent 0a60214 commit 3e3d007
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions great_expectations/validator/v1_validator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from copy import copy
from functools import cached_property
from typing import TYPE_CHECKING, Optional

Expand Down Expand Up @@ -125,9 +126,9 @@ def _validate_expectation_configs(

runtime_configuration: dict
if isinstance(self.result_format, ResultFormat):
runtime_configuration = {"result_format": self.result_format.value}
runtime_configuration = {"result_format": copy(self.result_format.value)}
else:
runtime_configuration = {"result_format": self.result_format}
runtime_configuration = {"result_format": copy(self.result_format)}

results = self._wrapped_validator.graph_validate(
configurations=processed_expectation_configs,
Expand Down
17 changes: 17 additions & 0 deletions tests/validator/test_v1_validator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from copy import copy
from pprint import pformat as pf
from unittest import mock

Expand Down Expand Up @@ -140,6 +141,22 @@ def test_result_format_complete(validator: Validator, failing_expectation: Expec
assert "unexpected_list" in result.result


@pytest.mark.unit
def test_v1_validator_doesnt_mutate_result_format(
validator: Validator, expectation_suite: ExpectationSuite
):
"""This test verifies a bugfix where the legacy Validator mutates a ResultFormat
dict provided by the user.
"""
result_format_dict = {
"result_format": "COMPLETE",
}
backup_result_format_dict = copy(result_format_dict)
validator.result_format = result_format_dict
validator.validate_expectation_suite(expectation_suite=expectation_suite)
assert result_format_dict == backup_result_format_dict


@pytest.mark.unit
def test_validate_expectation_success(validator: Validator, passing_expectation: Expectation):
result = validator.validate_expectation(passing_expectation)
Expand Down

0 comments on commit 3e3d007

Please sign in to comment.