Skip to content

Commit 3469ace

Browse files
maxi297octavia-squidington-iii
andauthored
fix: interpolation should not generate complex types (#579)
Co-authored-by: octavia-squidington-iii <[email protected]>
1 parent 2a5924f commit 3469ace

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

airbyte_cdk/sources/declarative/interpolation/jinja.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ def _literal_eval(self, result: Optional[str], valid_types: Optional[Tuple[Type[
127127
evaluated = ast.literal_eval(result) # type: ignore # literal_eval is able to handle None
128128
except (ValueError, SyntaxError):
129129
return result
130-
if not valid_types or (valid_types and isinstance(evaluated, valid_types)):
130+
if (not valid_types and not isinstance(evaluated, complex)) or (
131+
valid_types and isinstance(evaluated, valid_types)
132+
):
131133
return evaluated
132134
return result
133135

debug_manifest/debug_manifest.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
from typing import Any, Mapping
77

8-
from airbyte_cdk.entrypoint import launch
8+
from airbyte_cdk.entrypoint import AirbyteEntrypoint, launch
99
from airbyte_cdk.sources.declarative.yaml_declarative_source import (
1010
YamlDeclarativeSource,
1111
)
@@ -23,7 +23,17 @@ def debug_manifest(source: YamlDeclarativeSource, args: list[str]) -> None:
2323

2424

2525
if __name__ == "__main__":
26+
args = sys.argv[1:]
27+
catalog_path = AirbyteEntrypoint.extract_catalog(args)
28+
config_path = AirbyteEntrypoint.extract_config(args)
29+
state_path = AirbyteEntrypoint.extract_state(args)
30+
2631
debug_manifest(
27-
YamlDeclarativeSource(**configuration),
28-
sys.argv[1:],
32+
YamlDeclarativeSource(
33+
path_to_yaml="resources/manifest.yaml",
34+
catalog=YamlDeclarativeSource.read_catalog(catalog_path) if catalog_path else None,
35+
config=YamlDeclarativeSource.read_config(config_path) if config_path else None,
36+
state=YamlDeclarativeSource.read_state(state_path) if state_path else None,
37+
),
38+
args,
2939
)

unit_tests/sources/declarative/interpolation/test_jinja.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,6 @@ def test_get_missing_value_from_config():
2929
assert val is None
3030

3131

32-
@pytest.mark.parametrize(
33-
"valid_types, expected_value",
34-
[
35-
pytest.param((str,), "1234J", id="test_value_is_a_string_if_valid_types_is_str"),
36-
pytest.param(None, 1234j, id="test_value_is_interpreted_as_complex_number_by_default"),
37-
],
38-
)
39-
def test_get_value_with_complex_number(valid_types, expected_value):
40-
s = "{{ config['value'] }}"
41-
config = {"value": "1234J"}
42-
val = interpolation.eval(s, config, valid_types=valid_types)
43-
assert val == expected_value
44-
45-
4632
def test_get_value_from_stream_slice():
4733
s = "{{ stream_slice['date'] }}"
4834
config = {"date": "2022-01-01"}
@@ -357,3 +343,21 @@ def test_interpolation_private_partition_attribute():
357343
actual_output = JinjaInterpolation().eval(template, {}, **{"stream_slice": stream_slice})
358344

359345
assert actual_output == expected_output
346+
347+
348+
def test_given_complex_when_eval_then_return_string():
349+
s = "9173710294242221J"
350+
config = {}
351+
352+
val = interpolation.eval(s, config)
353+
354+
assert isinstance(val, str)
355+
356+
357+
def test_given_valid_type_complex_when_eval_then_return_string():
358+
s = "9173710294242221J"
359+
config = {}
360+
361+
val = interpolation.eval(s, config, valid_types=(complex,))
362+
363+
assert isinstance(val, complex)

0 commit comments

Comments
 (0)