Skip to content
Merged
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
4 changes: 3 additions & 1 deletion soda-core/src/soda_core/common/soda_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,9 @@ def _build_diagnostics_json_dict(check_result: CheckResult) -> Optional[dict]:

return {
# TODO: this default 0 value is here only because check.diagnostics.value is a required non-nullable field in the api.
"value": check_result.threshold_value or 0,
"value": int(check_result.threshold_value)
if isinstance(check_result.threshold_value, bool)
else (check_result.threshold_value or 0),
"fail": _build_fail_threshold(check_result),
"v4": _build_v4_diagnostics_check_type_json_dict(check_result),
}
Expand Down
30 changes: 29 additions & 1 deletion soda-tests/tests/unit/test_soda_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@
FailedContractSkeletonGenerationException,
SodaCloudException,
)
from soda_core.common.soda_cloud import ContractSkeletonGenerationState, SodaCloud
from soda_core.common.soda_cloud import (
ContractSkeletonGenerationState,
SodaCloud,
_build_diagnostics_json_dict,
)
from soda_core.common.yaml import ContractYamlSource, SodaCloudYamlSource
from soda_core.contracts.contract_publication import ContractPublicationResult
from soda_core.contracts.contract_verification import (
CheckOutcome,
CheckResult,
ContractVerificationResult,
PostProcessingStage,
PostProcessingStageState,
Expand Down Expand Up @@ -691,3 +697,25 @@ def test_trigger_contract_skeleton_generation__error(mock_post):
"token": "some_token",
},
)


@pytest.mark.parametrize(
"threshold_value, expected_diagnostics_value",
[
(True, 1),
(False, 0),
(42, 42),
(3.14, 3.14),
(0, 0),
(None, 0),
],
)
def test_build_diagnostics_json_dict_casts_bool_to_int(threshold_value, expected_diagnostics_value):
check_result = CheckResult(
check=mock.MagicMock(),
outcome=CheckOutcome.PASSED,
threshold_value=threshold_value,
)
diagnostics = _build_diagnostics_json_dict(check_result)
assert diagnostics["value"] == expected_diagnostics_value
assert not isinstance(diagnostics["value"], bool)
Loading