Skip to content

Commit

Permalink
[MAINTENANCE] Enable run_id overrides for Checkpoint and `Validat…
Browse files Browse the repository at this point in the history
…ionDefinition` (#9760)
  • Loading branch information
cdkini committed Apr 15, 2024
1 parent a2fe7d1 commit 7ecf3cf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
8 changes: 6 additions & 2 deletions great_expectations/checkpoint/v1_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@
)

CheckpointAction: TypeAlias = Union[
EmailAction,
MicrosoftTeamsNotificationAction,
OpsgenieAlertAction,
PagerdutyAlertAction,
SlackNotificationAction,
SNSNotificationAction,
StoreValidationResultAction,
UpdateDataDocsAction,
# NOTE: Currently placed last as the root validator emits warnings
# that aren't relevant to end users (unless they are using the action).
EmailAction,
]


Expand Down Expand Up @@ -161,8 +163,9 @@ def run(
self,
batch_parameters: Dict[str, Any] | None = None,
expectation_parameters: Dict[str, Any] | None = None,
run_id: RunIdentifier | None = None,
) -> CheckpointResult:
run_id = RunIdentifier(run_time=dt.datetime.now(dt.timezone.utc))
run_id = run_id or RunIdentifier(run_time=dt.datetime.now(dt.timezone.utc))
run_results = self._run_validation_definitions(
batch_parameters=batch_parameters,
expectation_parameters=expectation_parameters,
Expand Down Expand Up @@ -192,6 +195,7 @@ def _run_validation_definitions(
batch_parameters=batch_parameters,
suite_parameters=expectation_parameters,
result_format=result_format,
run_id=run_id,
)
key = self._build_result_key(
validation_definition=validation_definition,
Expand Down
16 changes: 13 additions & 3 deletions great_expectations/core/validation_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ def run(
batch_parameters: Optional[BatchParameters] = None,
suite_parameters: Optional[dict[str, Any]] = None,
result_format: ResultFormat = ResultFormat.SUMMARY,
run_id: RunIdentifier | None = None,
) -> ExpectationSuiteValidationResult:
validator = Validator(
batch_definition=self.batch_definition,
Expand All @@ -209,10 +210,17 @@ def run(
)
results = validator.validate_expectation_suite(self.suite, suite_parameters)

# NOTE: We should promote this to a top-level field of the result.
# Meta should be reserved for user-defined information.
if run_id:
results.meta["run_id"] = run_id

(
expectation_suite_identifier,
validation_result_id,
) = self._get_expectation_suite_and_validation_result_ids(validator)
) = self._get_expectation_suite_and_validation_result_ids(
validator=validator, run_id=run_id
)

ref = self._validation_results_store.store_validation_results(
suite_validation_result=results,
Expand All @@ -230,6 +238,7 @@ def run(
def _get_expectation_suite_and_validation_result_ids(
self,
validator: Validator,
run_id: RunIdentifier | None = None,
) -> (
tuple[GXCloudIdentifier, GXCloudIdentifier]
| tuple[ExpectationSuiteIdentifier, ValidationResultIdentifier]
Expand All @@ -246,8 +255,9 @@ def _get_expectation_suite_and_validation_result_ids(
)
return expectation_suite_identifier, validation_result_id
else:
run_time = datetime.datetime.now(tz=datetime.timezone.utc)
run_id = RunIdentifier(run_time=run_time)
run_id = run_id or RunIdentifier(
run_time=datetime.datetime.now(tz=datetime.timezone.utc)
)
expectation_suite_identifier = ExpectationSuiteIdentifier(name=self.suite.name)
validation_result_id = ValidationResultIdentifier(
batch_identifier=validator.active_batch_id,
Expand Down
4 changes: 2 additions & 2 deletions great_expectations/render/renderer/page_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def render(
):
# Gather run identifiers
run_name, run_time = self._parse_run_values(validation_results)
expectation_suite_name = validation_results.meta["expectation_suite_name"]
expectation_suite_name = validation_results.suite_name
batch_kwargs = (
validation_results.meta.get("batch_kwargs", {})
or validation_results.meta.get("batch_spec", {})
Expand Down Expand Up @@ -356,7 +356,7 @@ def _get_meta_properties_notes(cls, suite_meta):
@classmethod
def _render_validation_header(cls, validation_results):
success = validation_results.success
expectation_suite_name = validation_results.meta["expectation_suite_name"]
expectation_suite_name = validation_results.suite_name
expectation_suite_path_components = (
[".." for _ in range(len(expectation_suite_name.split(".")) + 3)]
+ ["expectations"]
Expand Down
1 change: 1 addition & 0 deletions tests/checkpoint/test_v1_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ def test_checkpoint_run_passes_through_runtime_params(
batch_parameters=batch_parameters,
suite_parameters=expectation_parameters,
result_format=ResultFormat.SUMMARY,
run_id=mock.ANY,
)

@pytest.mark.unit
Expand Down

0 comments on commit 7ecf3cf

Please sign in to comment.