diff --git a/airbyte_cdk/sources/declarative/transformations/add_fields.py b/airbyte_cdk/sources/declarative/transformations/add_fields.py index f18b1b70a..08de277eb 100644 --- a/airbyte_cdk/sources/declarative/transformations/add_fields.py +++ b/airbyte_cdk/sources/declarative/transformations/add_fields.py @@ -139,7 +139,9 @@ def transform( valid_types = (parsed_field.value_type,) if parsed_field.value_type else None value = parsed_field.value.eval(config, valid_types=valid_types, **kwargs) is_empty_condition = not self.condition - if is_empty_condition or self._filter_interpolator.eval(config, value=value, **kwargs): + if is_empty_condition or self._filter_interpolator.eval( + config, value=value, path=parsed_field.path, **kwargs + ): dpath.new(record, parsed_field.path, value) def __eq__(self, other: Any) -> bool: diff --git a/unit_tests/sources/declarative/transformations/test_add_fields.py b/unit_tests/sources/declarative/transformations/test_add_fields.py index 2d8650291..94b6f07ed 100644 --- a/unit_tests/sources/declarative/transformations/test_add_fields.py +++ b/unit_tests/sources/declarative/transformations/test_add_fields.py @@ -176,6 +176,24 @@ {"k": "v", "path": "static_value"}, id="add all fields if condition is boolean True", ), + pytest.param( + {"k": "v"}, + [(["path"], "static_value")], + None, + "{{ path[0] not in record.keys() }}", + {}, + {"k": "v", "path": "static_value"}, + id="add fields when condition uses path value", + ), + pytest.param( + {"k": "v", "existing_path": "record_value"}, + [(["existing_path"], "static_value")], + None, + "{{ path[0] not in record.keys() }}", + {}, + {"k": "v", "existing_path": "record_value"}, + id="do not add fields when condition uses path value", + ), ], ) def test_add_fields(