Skip to content

Commit 99a1a96

Browse files
authored
feat: update DpathValidator to skip validation if returned value is falsy (#590)
1 parent f398ab6 commit 99a1a96

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

airbyte_cdk/sources/declarative/validators/dpath_validator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ def validate(self, input_data: dict[str, Any]) -> None:
4747
if "*" in path:
4848
try:
4949
values = dpath.values(input_data, path)
50+
if not values:
51+
return
5052
for value in values:
5153
self.strategy.validate(value)
5254
except KeyError as e:
5355
raise ValueError(f"Error validating path '{self.field_path}': {e}")
5456
else:
5557
try:
5658
value = dpath.get(input_data, path)
59+
if not value:
60+
return
5761
self.strategy.validate(value)
5862
except KeyError as e:
5963
raise ValueError(f"Error validating path '{self.field_path}': {e}")

unit_tests/sources/declarative/validators/test_dpath_validator.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
2+
13
from unittest import TestCase
24

35
import pytest
@@ -90,3 +92,13 @@ def test_path_with_wildcard_when_validate_then_validate_is_successful(self):
9092
assert strategy.validate_called
9193
assert strategy.validated_value in ["[email protected]", "[email protected]"]
9294
self.assertIn(strategy.validated_value, ["[email protected]", "[email protected]"])
95+
96+
def test_given_no_values_when_validate_then_validate_is_not_called(self):
97+
strategy = MockValidationStrategy()
98+
validator = DpathValidator(field_path=["users", "*", "email"], strategy=strategy)
99+
100+
validator.validate({"users": {}})
101+
validator.validate(None)
102+
validator.validate({"users": [{"name": "Octavia"}]})
103+
104+
assert not strategy.validate_called

0 commit comments

Comments
 (0)