-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
🐛 [low-code] $options shouldn't overwrite values that are already defined #18060
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cffd941
fix
girarda e9e54ce
Add missing test
girarda d98bc66
remove prints
girarda da275b0
extract to method
girarda 19687bf
rename
girarda e0115d0
Add missing test
girarda 10ae205
rename
girarda 34a6167
Merge branch 'master' into alex/fix_create_partial
girarda 13b545d
bump
girarda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ | |
# Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from airbyte_cdk.sources.declarative.create_partial import create | ||
import pytest | ||
from airbyte_cdk.sources.declarative.create_partial import _key_is_unset_or_identical, create | ||
from airbyte_cdk.sources.declarative.interpolation.interpolated_string import InterpolatedString | ||
|
||
|
||
|
@@ -33,6 +34,12 @@ def test_pass_parameter_to_create_function(): | |
assert object.another_param == "B" | ||
|
||
|
||
def test_parameter_not_overwritten_by_options(): | ||
object = create(AClass, parameter="A", another_param="B", **{"$options": {"parameter": "C"}})() | ||
assert object.parameter == "A" | ||
assert object.another_param == "B" | ||
|
||
|
||
def test_overwrite_param(): | ||
object = create(AClass, parameter="A", another_param="B")(parameter="C") | ||
assert object.parameter == "C" | ||
|
@@ -46,7 +53,7 @@ def test_string_interpolation(): | |
assert interpolated_string.string == s | ||
|
||
|
||
def test_string_interpolation_through_kwargs(): | ||
def test_string_interpolation_through_options(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename test |
||
s = "{{ options['name'] }}" | ||
options = {"name": "airbyte"} | ||
partial = create(InterpolatedString, string=s, **options) | ||
|
@@ -60,3 +67,17 @@ def test_string_interpolation_through_options_keyword(): | |
partial = create(InterpolatedString, string=s, **options) | ||
interpolated_string = partial() | ||
assert interpolated_string.eval({}) == "airbyte" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"test_name, key, value, expected_result", | ||
[ | ||
("test", "key", "value", True), | ||
("test", "key", "a_different_value", False), | ||
("test", "a_different_key", "value", True), | ||
], | ||
) | ||
def test_key_is_unset_or_identical(test_name, key, value, expected_result): | ||
mapping = {"key": "value"} | ||
result = _key_is_unset_or_identical(key, value, mapping) | ||
assert expected_result == result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -414,31 +414,31 @@ def test_create_record_selector(test_name, record_selector, expected_runtime_sel | |
( | ||
"test_option_in_selector", | ||
""" | ||
extractor: | ||
type: DpathExtractor | ||
field_pointer: ["{{ options['name'] }}"] | ||
selector: | ||
class_name: airbyte_cdk.sources.declarative.extractors.record_selector.RecordSelector | ||
$options: | ||
name: "selector" | ||
extractor: "*ref(extractor)" | ||
""", | ||
extractor: | ||
type: DpathExtractor | ||
field_pointer: ["{{ options['name'] }}"] | ||
selector: | ||
class_name: airbyte_cdk.sources.declarative.extractors.record_selector.RecordSelector | ||
$options: | ||
name: "selector" | ||
extractor: "*ref(extractor)" | ||
""", | ||
"selector", | ||
), | ||
( | ||
"test_option_in_extractor", | ||
""" | ||
extractor: | ||
type: DpathExtractor | ||
$options: | ||
name: "extractor" | ||
field_pointer: ["{{ options['name'] }}"] | ||
selector: | ||
class_name: airbyte_cdk.sources.declarative.extractors.record_selector.RecordSelector | ||
$options: | ||
name: "selector" | ||
extractor: "*ref(extractor)" | ||
""", | ||
extractor: | ||
type: DpathExtractor | ||
$options: | ||
name: "extractor" | ||
field_pointer: ["{{ options['name'] }}"] | ||
selector: | ||
class_name: airbyte_cdk.sources.declarative.extractors.record_selector.RecordSelector | ||
$options: | ||
name: "selector" | ||
extractor: "*ref(extractor)" | ||
""", | ||
"extractor", | ||
), | ||
], | ||
|
@@ -682,6 +682,37 @@ def test_add_fields(self): | |
] | ||
assert expected == component.transformations | ||
|
||
def test_add_fields_path_in_options(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I confirmed this test fails without the changes to create_partial.py |
||
content = f""" | ||
the_stream: | ||
class_name: airbyte_cdk.sources.declarative.declarative_stream.DeclarativeStream | ||
$options: | ||
{self.base_options} | ||
path: "/wrong_path" | ||
transformations: | ||
- type: AddFields | ||
fields: | ||
- path: ["field1"] | ||
value: "static_value" | ||
""" | ||
config = parser.parse(content) | ||
|
||
factory.create_component(config["the_stream"], input_config, False) | ||
|
||
component = factory.create_component(config["the_stream"], input_config)() | ||
assert isinstance(component, DeclarativeStream) | ||
expected = [ | ||
AddFields( | ||
fields=[ | ||
AddedFieldDefinition( | ||
path=["field1"], value=InterpolatedString(string="static_value", default="static_value", options={}), options={} | ||
) | ||
], | ||
options={}, | ||
) | ||
] | ||
assert expected == component.transformations | ||
|
||
|
||
def test_validation_wrong_input_type(): | ||
content = """ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirmed this test fails without the changes to create_partial.py