Skip to content

Commit 348805a

Browse files
darynaishchenkooctavia-squidington-iii
and
octavia-squidington-iii
authored
feat(low code cdk): add path to filter interpolation in AddFields condition (#454)
Co-authored-by: octavia-squidington-iii <[email protected]>
1 parent b9f84d5 commit 348805a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

airbyte_cdk/sources/declarative/transformations/add_fields.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ def transform(
139139
valid_types = (parsed_field.value_type,) if parsed_field.value_type else None
140140
value = parsed_field.value.eval(config, valid_types=valid_types, **kwargs)
141141
is_empty_condition = not self.condition
142-
if is_empty_condition or self._filter_interpolator.eval(config, value=value, **kwargs):
142+
if is_empty_condition or self._filter_interpolator.eval(
143+
config, value=value, path=parsed_field.path, **kwargs
144+
):
143145
dpath.new(record, parsed_field.path, value)
144146

145147
def __eq__(self, other: Any) -> bool:

unit_tests/sources/declarative/transformations/test_add_fields.py

+18
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,24 @@
176176
{"k": "v", "path": "static_value"},
177177
id="add all fields if condition is boolean True",
178178
),
179+
pytest.param(
180+
{"k": "v"},
181+
[(["path"], "static_value")],
182+
None,
183+
"{{ path[0] not in record.keys() }}",
184+
{},
185+
{"k": "v", "path": "static_value"},
186+
id="add fields when condition uses path value",
187+
),
188+
pytest.param(
189+
{"k": "v", "existing_path": "record_value"},
190+
[(["existing_path"], "static_value")],
191+
None,
192+
"{{ path[0] not in record.keys() }}",
193+
{},
194+
{"k": "v", "existing_path": "record_value"},
195+
id="do not add fields when condition uses path value",
196+
),
179197
],
180198
)
181199
def test_add_fields(

0 commit comments

Comments
 (0)