Skip to content
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

CDK: make TypeTransformer more robust to incorrect incoming records #16544

Merged
merged 8 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.1.84
- Make TypeTransformer more robust to incorrect incoming records

## 0.1.83
- Fix per-stream to send legacy format for connectors that override read

Expand Down
8 changes: 4 additions & 4 deletions airbyte-cdk/python/airbyte_cdk/sources/utils/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ def resolve(subschema):
return subschema

# Transform object and array values before running json schema type checking for each element.
if schema_key == "properties":
if schema_key == "properties" and isinstance(instance, dict):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add the comment you added in the PR description as a source code comment to clarify for the next developer reading this why we verify the isinstance?

for k, subschema in property_value.items():
if k in (instance or {}):
if k in instance:
subschema = resolve(subschema)
instance[k] = self.__normalize(instance[k], subschema)
elif schema_key == "items":
elif schema_key == "items" and isinstance(instance, list):
subschema = resolve(property_value)
for index, item in enumerate((instance or [])):
for index, item in enumerate(instance):
instance[index] = self.__normalize(item, subschema)

# Running native jsonschema traverse algorithm after field normalization is done.
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.1.83",
version="0.1.84",
description="A framework for writing Airbyte Connectors.",
long_description=README,
long_description_content_type="text/markdown",
Expand Down
12 changes: 12 additions & 0 deletions airbyte-cdk/python/unit_tests/sources/utils/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@
{"cpc": 6.6666},
None,
),
(
{"type": "object", "properties": {"value": {"type": "array", "items": {"type": "string"}}}},
{"value": {"key": "value"}},
{"value": {"key": "value"}},
"{'key': 'value'} is not of type 'array'",
),
(
{"type": "object", "properties": {"value1": {"type": "object", "properties": {"value2": {"type": "string"}}}}},
{"value1": "value2"},
{"value1": "value2"},
"'value2' is not of type 'object'",
),
],
)
def test_transform(schema, actual, expected, expected_warns, caplog):
Expand Down