From 79cb1c1022a93244733239d983f981d411ed18c7 Mon Sep 17 00:00:00 2001 From: darynaishchenko Date: Tue, 1 Apr 2025 13:42:49 +0300 Subject: [PATCH 1/2] add path to filter interpolation in AddFields condition --- .../declarative/transformations/add_fields.py | 2 +- .../transformations/test_add_fields.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/airbyte_cdk/sources/declarative/transformations/add_fields.py b/airbyte_cdk/sources/declarative/transformations/add_fields.py index f18b1b70a..fb84b5bcd 100644 --- a/airbyte_cdk/sources/declarative/transformations/add_fields.py +++ b/airbyte_cdk/sources/declarative/transformations/add_fields.py @@ -139,7 +139,7 @@ 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( From be21e835304c5a8a5acfbaa33d5f9fa3bb47ce77 Mon Sep 17 00:00:00 2001 From: octavia-squidington-iii Date: Tue, 1 Apr 2025 10:52:47 +0000 Subject: [PATCH 2/2] Auto-fix lint and format issues --- airbyte_cdk/sources/declarative/transformations/add_fields.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/airbyte_cdk/sources/declarative/transformations/add_fields.py b/airbyte_cdk/sources/declarative/transformations/add_fields.py index fb84b5bcd..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, path=parsed_field.path, **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: