From 5cd88e7c057e95b28b0b7b27775d03d6aba1caca Mon Sep 17 00:00:00 2001 From: Serhii Chvaliuk Date: Fri, 11 Nov 2022 10:44:23 +0200 Subject: [PATCH] CDK: don't filter failed interpolated vars for `request_options_provider.request_body_json` (#19297) Signed-off-by: Sergey Chvalyuk --- airbyte-cdk/python/CHANGELOG.md | 3 +++ .../airbyte_cdk/sources/declarative/auth/oauth.py | 2 +- .../interpolated_request_input_provider.py | 2 +- .../http/requests_native_auth/abstract_oauth.py | 2 +- .../streams/http/requests_native_auth/oauth.py | 2 +- airbyte-cdk/python/setup.py | 2 +- .../test_interpolated_request_options_provider.py | 14 ++++++++++++-- 7 files changed, 20 insertions(+), 7 deletions(-) diff --git a/airbyte-cdk/python/CHANGELOG.md b/airbyte-cdk/python/CHANGELOG.md index 384f1b232d29..d14aab7d1c39 100644 --- a/airbyte-cdk/python/CHANGELOG.md +++ b/airbyte-cdk/python/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 0.9.1 +Low-code: Fix filtering vars in `InterpolatedRequestInputProvider.eval_request_inputs` + ## 0.9.0 Low-code: Allow `grant_type` to be specified for OAuthAuthenticator diff --git a/airbyte-cdk/python/airbyte_cdk/sources/declarative/auth/oauth.py b/airbyte-cdk/python/airbyte_cdk/sources/declarative/auth/oauth.py index 7fc314c7e71f..97869cc9010a 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/declarative/auth/oauth.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/declarative/auth/oauth.py @@ -84,7 +84,7 @@ def get_access_token_name(self) -> InterpolatedString: def get_expires_in_name(self) -> InterpolatedString: return self.expires_in_name.eval(self.config) - + def get_grant_type(self) -> InterpolatedString: return self.grant_type.eval(self.config) diff --git a/airbyte-cdk/python/airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_input_provider.py b/airbyte-cdk/python/airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_input_provider.py index 370e5d8caeac..731b7e63e0f3 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_input_provider.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_input_provider.py @@ -45,6 +45,6 @@ def eval_request_inputs( interpolated_value = self._interpolator.eval(self.config, **kwargs) if isinstance(interpolated_value, dict): - non_null_tokens = {k: v for k, v in interpolated_value.items() if v} + non_null_tokens = {k: v for k, v in interpolated_value.items() if v is not None} return non_null_tokens return interpolated_value diff --git a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py index 843e333cbf07..e7e0ce397e80 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py @@ -117,7 +117,7 @@ def get_expires_in_name(self) -> str: @abstractmethod def get_refresh_request_body(self) -> Mapping[str, Any]: """Returns the request body to set on the refresh request""" - + @abstractmethod def get_grant_type(self) -> str: """Returns grant_type specified for requesting access_token""" diff --git a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py index 40d33dd9383d..5f2e21df8841 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py @@ -63,7 +63,7 @@ def get_expires_in_name(self) -> str: def get_refresh_request_body(self) -> Mapping[str, Any]: return self._refresh_request_body - + def get_grant_type(self) -> str: return self._grant_type diff --git a/airbyte-cdk/python/setup.py b/airbyte-cdk/python/setup.py index 773743d05205..c0c0743d3f07 100644 --- a/airbyte-cdk/python/setup.py +++ b/airbyte-cdk/python/setup.py @@ -15,7 +15,7 @@ setup( name="airbyte-cdk", - version="0.8.1", + version="0.9.1", description="A framework for writing Airbyte Connectors.", long_description=README, long_description_content_type="text/markdown", diff --git a/airbyte-cdk/python/unit_tests/sources/declarative/requesters/request_options/test_interpolated_request_options_provider.py b/airbyte-cdk/python/unit_tests/sources/declarative/requesters/request_options/test_interpolated_request_options_provider.py index 457ddc9a22d8..59cbcd100c7b 100644 --- a/airbyte-cdk/python/unit_tests/sources/declarative/requesters/request_options/test_interpolated_request_options_provider.py +++ b/airbyte-cdk/python/unit_tests/sources/declarative/requesters/request_options/test_interpolated_request_options_provider.py @@ -21,12 +21,17 @@ ("test_value_depends_on_stream_slice", {"read_from_slice": "{{ stream_slice['start_date'] }}"}, {"read_from_slice": "2020-01-01"}), ("test_value_depends_on_next_page_token", {"read_from_token": "{{ next_page_token['offset'] }}"}, {"read_from_token": 12345}), ("test_value_depends_on_config", {"read_from_config": "{{ config['option'] }}"}, {"read_from_config": "OPTION"}), - ("test_none_value", {"missing_param": "{{ fake_path['date'] }}"}, {}), + ("test_missing_value", {"missing_param": "{{ fake_path['date'] }}"}, {}), ( "test_parameter_is_interpolated", {"{{ stream_state['date'] }} - {{stream_slice['start_date']}} - {{next_page_token['offset']}} - {{config['option']}}": "ABC"}, {"2021-01-01 - 2020-01-01 - 12345 - OPTION": "ABC"}, ), + ("test_boolean_false_value", {"boolean_false": "{{ False }}"}, {"boolean_false": False}), + ("test_integer_falsy_value", {"integer_falsy": "{{ 0 }}"}, {"integer_falsy": 0}), + ("test_number_falsy_value", {"number_falsy": "{{ 0.0 }}"}, {"number_falsy": 0.0}), + ("test_string_falsy_value", {"string_falsy": "{{ '' }}"}, {}), + ("test_none_value", {"none_value": "{{ None }}"}, {}), ], ) def test_interpolated_request_params(test_name, input_request_params, expected_request_params): @@ -45,12 +50,17 @@ def test_interpolated_request_params(test_name, input_request_params, expected_r ("test_value_depends_on_stream_slice", {"read_from_slice": "{{ stream_slice['start_date'] }}"}, {"read_from_slice": "2020-01-01"}), ("test_value_depends_on_next_page_token", {"read_from_token": "{{ next_page_token['offset'] }}"}, {"read_from_token": 12345}), ("test_value_depends_on_config", {"read_from_config": "{{ config['option'] }}"}, {"read_from_config": "OPTION"}), - ("test_none_value", {"missing_json": "{{ fake_path['date'] }}"}, {}), + ("test_missing_value", {"missing_json": "{{ fake_path['date'] }}"}, {}), ( "test_interpolated_keys", {"{{ stream_state['date'] }}": 123, "{{ config['option'] }}": "ABC"}, {"2021-01-01": 123, "OPTION": "ABC"}, ), + ("test_boolean_false_value", {"boolean_false": "{{ False }}"}, {"boolean_false": False}), + ("test_integer_falsy_value", {"integer_falsy": "{{ 0 }}"}, {"integer_falsy": 0}), + ("test_number_falsy_value", {"number_falsy": "{{ 0.0 }}"}, {"number_falsy": 0.0}), + ("test_string_falsy_value", {"string_falsy": "{{ '' }}"}, {}), + ("test_none_value", {"none_value": "{{ None }}"}, {}), ], ) def test_interpolated_request_json(test_name, input_request_json, expected_request_json):