Skip to content

CDK: don't filter failed interpolated vars for request_options_provider.request_body_json #19297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Nov 11, 2022
3 changes: 3 additions & 0 deletions airbyte-cdk/python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.8.1
Low-code: Don't filter falsy interpolated vars for `request_options_provider.request_body_json`

## 0.8.0
Low-code: Allow for request and response to be emitted as log messages

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class InterpolatedRequestInputProvider:
config: Config = field(default_factory=dict)
_interpolator: Union[InterpolatedString, InterpolatedMapping] = field(init=False, repr=False, default=None)
_request_inputs: Union[str, Mapping[str, str]] = field(init=False, repr=False, default=None)
filter_items: bool = True

def __post_init__(self, options: Mapping[str, Any]):

Expand All @@ -43,8 +44,6 @@ def eval_request_inputs(
"""
kwargs = {"stream_state": stream_state, "stream_slice": stream_slice, "next_page_token": next_page_token}
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}
return non_null_tokens
if self.filter_items and isinstance(interpolated_value, dict):
interpolated_value = {k: v for k, v in interpolated_value.items() if v}
return interpolated_value
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __post_init__(self, options: Mapping[str, Any]):
config=self.config, request_inputs=self.request_body_data, options=options
)
self._body_json_interpolator = InterpolatedRequestInputProvider(
config=self.config, request_inputs=self.request_body_json, options=options
config=self.config, request_inputs=self.request_body_json, options=options, filter_items=False
)

def get_request_params(
Expand Down
2 changes: 1 addition & 1 deletion airbyte-cdk/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name="airbyte-cdk",
version="0.8.0",
version="0.8.1",
description="A framework for writing Airbyte Connectors.",
long_description=README,
long_description_content_type="text/markdown",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"}, {}),
("test_integer_falsy_value", {"integer_falsy": "{{ 0 }}"}, {}),
("test_number_falsy_value", {"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):
Expand All @@ -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'] }}"}, {"missing_json": None}),
(
"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": "{{ '' }}"}, {"string_falsy": None}),
("test_none_value", {"none_value": "{{ None }}"}, {"none_value": None}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when would we want to return None in the request body?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory I can imagine something like this:

curl -d '{"key1":null}' -X POST http://api.com/api

But to be honest we did not encounter in this for now. For now we need only this:

curl -d '{"key1":false}' -X POST http://api.com/api

I have re-implemented doing less radical changes
What do you think now?

],
)
def test_interpolated_request_json(test_name, input_request_json, expected_request_json):
Expand Down