Skip to content

Commit

Permalink
[MAINTENANCE] ensure run_id on ValidationDefinition.run (#10909)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-stauffer authored Feb 3, 2025
1 parent 5941bc8 commit 4a937b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions great_expectations/core/validation_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,11 @@ def run(

# 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
results.meta["validation_time"] = run_id.run_time
if not run_id:
run_id = RunIdentifier(run_time=datetime.datetime.now(datetime.timezone.utc))
results.meta["run_id"] = run_id
results.meta["validation_time"] = run_id.run_time

if batch_parameters:
batch_parameters_copy = {k: v for k, v in batch_parameters.items()}
if "dataframe" in batch_parameters_copy:
Expand Down
15 changes: 15 additions & 0 deletions tests/core/test_validation_definition.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from __future__ import annotations

import datetime
import json
import uuid
from typing import TYPE_CHECKING, Type
from unittest import mock
from unittest.mock import ANY

import pandas as pd
import pytest

import great_expectations as gx
import great_expectations.expectations as gxe
from great_expectations import RunIdentifier
from great_expectations import __version__ as GX_VERSION
from great_expectations.core.batch_definition import BatchDefinition
from great_expectations.core.expectation_suite import ExpectationSuite
Expand Down Expand Up @@ -305,7 +308,11 @@ def test_adds_requisite_fields(
"batch_markers": BATCH_MARKERS,
"active_batch_definition": ACTIVE_BATCH_DEFINITION,
"great_expectations_version": GX_VERSION,
"run_id": ANY,
"validation_time": ANY,
}
assert isinstance(output.meta["run_id"], RunIdentifier)
assert isinstance(output.meta["validation_time"], datetime.datetime)

@pytest.mark.unit
def test_adds_correct_batch_parameter_field_for_dataframes(
Expand All @@ -328,7 +335,11 @@ def test_adds_correct_batch_parameter_field_for_dataframes(
"batch_markers": BATCH_MARKERS,
"active_batch_definition": ACTIVE_BATCH_DEFINITION,
"great_expectations_version": GX_VERSION,
"run_id": ANY,
"validation_time": ANY,
}
assert isinstance(output.meta["run_id"], RunIdentifier)
assert isinstance(output.meta["validation_time"], datetime.datetime)

@pytest.mark.parametrize(
"batch_parameters",
Expand Down Expand Up @@ -360,7 +371,11 @@ def test_adds_correct_batch_parameter_fields_for_postgres(
"batch_markers": BATCH_MARKERS,
"active_batch_definition": ACTIVE_BATCH_DEFINITION,
"great_expectations_version": GX_VERSION,
"run_id": ANY,
"validation_time": ANY,
}
assert isinstance(output.meta["run_id"], RunIdentifier)
assert isinstance(output.meta["validation_time"], datetime.datetime)

@mock.patch.object(ValidationResultsStore, "set")
@pytest.mark.unit
Expand Down

0 comments on commit 4a937b3

Please sign in to comment.