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

SAT: all additionalProperties fields must be set to true #14878

Merged
merged 9 commits into from
Jul 22, 2022

Conversation

alafanechere
Copy link
Contributor

@alafanechere alafanechere commented Jul 20, 2022

What

Closing #14600
Add tests to make sure all the connector setting the additionalProperties field in their spec or stream schema set the value of this field to true. Check #14196 to understand why this is required.

How

🚨 User Impact 🚨

I think this will cause a lot of build failures because a lot of connectors are not following this rule and use "additionalProperties" : false.

I think we also need to update our tutorials and code generation template (*.hbs) that are using "additionalProperties": false. I created an issue for this.

@alafanechere
Copy link
Contributor Author

alafanechere commented Jul 20, 2022

/test connector=bases/source-acceptance-test

🕑 bases/source-acceptance-test https://github.com/airbytehq/airbyte/actions/runs/2704924511
✅ bases/source-acceptance-test https://github.com/airbytehq/airbyte/actions/runs/2704924511
No Python unittests run

Build Passed

Test summary info:

All Passed

@alafanechere
Copy link
Contributor Author

I'm going to test if running test with the slash command uses a dev image of SAT and run a test for connectors that whose acceptance tests should failed on:

  • source-open-weather's spec has "additionalProperties": false
  • source-amazon-seller-partner has streams with "additionalProperties": false

@alafanechere
Copy link
Contributor Author

alafanechere commented Jul 20, 2022

/test connector=connectors/source-openweather

🕑 connectors/source-openweather https://github.com/airbytehq/airbyte/actions/runs/2704938055
❌ connectors/source-openweather https://github.com/airbytehq/airbyte/actions/runs/2704938055
🐛 https://gradle.com/s/7ymtq57svny6s

Build Failed

Test summary info:

=========================== short test summary info ============================
FAILED test_core.py::TestSpec::test_additional_properties_is_true[inputs0] - ...
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/source_acceptance_test/plugin.py:56: Skipping TestFullRefresh.test_sequential_reads because not found in the config
=================== 1 failed, 25 passed, 1 skipped in 21.35s ===================

@alafanechere
Copy link
Contributor Author

alafanechere commented Jul 20, 2022

/test connector=connectors/source-amazon-seller-partner

🕑 connectors/source-amazon-seller-partner https://github.com/airbytehq/airbyte/actions/runs/2704939369
❌ connectors/source-amazon-seller-partner https://github.com/airbytehq/airbyte/actions/runs/2704939369
🐛 https://gradle.com/s/ld3gpfmarbcvw

Build Failed

Test summary info:

=========================== short test summary info ============================
FAILED test_core.py::TestDiscovery::test_additional_properties_is_true[inputs0]
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/source_acceptance_test/plugin.py:56: Skipping TestBasicRead.test_read because not found in the config
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/source_acceptance_test/plugin.py:56: Skipping TestFullRefresh.test_sequential_reads because not found in the config
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/source_acceptance_test/plugin.py:56: Skipping TestIncremental.test_two_sequential_reads because not found in the config
=================== 1 failed, 19 passed, 3 skipped in 6.56s ====================

@alafanechere
Copy link
Contributor Author

☝️ Both test failures above are expected and show that the new tests work as expected.

Copy link
Contributor

@pedroslopez pedroslopez left a comment

Choose a reason for hiding this comment

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

Nice job 👍🏼

There's an existing helper method that could have been used here, but I'll leave it up to you if you want to move over to that or keep the new one. My initial thought would be to use one or the other since they're so similar.

With regards to this change breaking builds for many connectors, do you know how many (python) sources are affected? We should check in with the dbs/dws team on priority for this existing issue #14718. If it will be done soon then maybe we hold off as to not impact publishes, if not then we could prioritize GA/Beta connectors and do those first.

Comment on lines +119 to +129
def find_all_values_for_key_in_schema(schema: dict, searched_key: str):
"""Retrieve all (nested) values in a schema for a specific searched key"""
if isinstance(schema, list):
for schema_item in schema:
yield from find_all_values_for_key_in_schema(schema_item, searched_key)
if isinstance(schema, dict):
for key, value in schema.items():
if key == searched_key:
yield value
if isinstance(value, dict) or isinstance(value, list):
yield from find_all_values_for_key_in_schema(value, searched_key)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not directly equivalent since this new method retrieves all values, but the existing find_key_inside_schema method can be used to find the first instance of a given key (e.g. find_key_inside_schema(schema, "additionalProperties") would return {"additionalProperties": False} or None if not found)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep I tried find_key_inside_schema, it's indeed working but only returns the first schema item having the searched key. I could have implemented a recursion in the final test function to use this function. But I preferred to use my new function to defer the recursion to the helper to boost the readability of the test. And this function can be helpful in the future if we have other keys we want to validate value on.

@alafanechere
Copy link
Contributor Author

alafanechere commented Jul 21, 2022

My initial thought would be to use one or the other since they're so similar.

@pedroslopez
I replaced find_key_inside_schema with find_all_values_for_key_in_schema in tests checking for $ref. Original unit tests on functions that used find_key_inside_schema are still passing.

@alafanechere
Copy link
Contributor Author

do you know how many (python) sources are affected

I created a list I shared in #14718

@alafanechere
Copy link
Contributor Author

alafanechere commented Jul 21, 2022

/test connector=connectors/source-amplitude

🕑 connectors/source-amplitude https://github.com/airbytehq/airbyte/actions/runs/2712454558
❌ connectors/source-amplitude https://github.com/airbytehq/airbyte/actions/runs/2712454558
🐛 https://gradle.com/s/i6oqeh4t3uhw4

Build Failed

Test summary info:

=========================== short test summary info ============================
FAILED test_core.py::TestSpec::test_additional_properties_is_true[inputs0] - ...
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/source_acceptance_test/tests/test_incremental.py:23: `future_state_path` not specified, skipping
============= 1 failed, 25 passed, 1 skipped in 191.57s (0:03:11) ==============

@alafanechere
Copy link
Contributor Author

alafanechere commented Jul 22, 2022

I made the required changes to beta and GA source (non-jdbc) connectors in #14924

@alafanechere
Copy link
Contributor Author

alafanechere commented Jul 22, 2022

/test connector=connectors/source-amplitude

🕑 connectors/source-amplitude https://github.com/airbytehq/airbyte/actions/runs/2717953897
✅ connectors/source-amplitude https://github.com/airbytehq/airbyte/actions/runs/2717953897
Python tests coverage:

Name                                                 Stmts   Miss  Cover
------------------------------------------------------------------------
source_acceptance_test/utils/__init__.py                 6      0   100%
source_acceptance_test/tests/__init__.py                 4      0   100%
source_acceptance_test/__init__.py                       2      0   100%
source_acceptance_test/tests/test_full_refresh.py       52      2    96%
source_acceptance_test/utils/asserts.py                 37      2    95%
source_acceptance_test/config.py                        77      6    92%
source_acceptance_test/utils/json_schema_helper.py     105     13    88%
source_acceptance_test/tests/test_incremental.py       121     25    79%
source_acceptance_test/utils/common.py                  77     17    78%
source_acceptance_test/tests/test_core.py              307    106    65%
source_acceptance_test/utils/compare.py                 62     23    63%
source_acceptance_test/base.py                          10      4    60%
source_acceptance_test/utils/connector_runner.py       110     48    56%
------------------------------------------------------------------------
TOTAL                                                  970    246    75%
Name                           Stmts   Miss  Cover
--------------------------------------------------
source_amplitude/source.py        24      0   100%
source_amplitude/__init__.py       2      0   100%
source_amplitude/errors.py        12      1    92%
source_amplitude/api.py          170     22    87%
--------------------------------------------------
TOTAL                            208     23    89%

Build Passed

Test summary info:

=========================== short test summary info ============================
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/source_acceptance_test/tests/test_incremental.py:23: `future_state_path` not specified, skipping
================== 26 passed, 1 skipped in 149.73s (0:02:29) ===================

@alafanechere
Copy link
Contributor Author

☝️ The test above should now pass after #14924 was merged

@alafanechere
Copy link
Contributor Author

alafanechere commented Jul 22, 2022

/publish connector=bases/source-acceptance-test auto-bump-version=false

🕑 Publishing the following connectors:
bases/source-acceptance-test
https://github.com/airbytehq/airbyte/actions/runs/2718343998


Connector Did it publish? Were definitions generated?
bases/source-acceptance-test

if you have connectors that successfully published but failed definition generation, follow step 4 here ▶️

@alafanechere
Copy link
Contributor Author

alafanechere commented Jul 22, 2022

/publish connector=bases/source-acceptance-test auto-bump-version=false

🕑 Publishing the following connectors:
bases/source-acceptance-test
https://github.com/airbytehq/airbyte/actions/runs/2718686815


Connector Did it publish? Were definitions generated?
bases/source-acceptance-test

if you have connectors that successfully published but failed definition generation, follow step 4 here ▶️

@alafanechere alafanechere merged commit 54b003b into master Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SAT: Assert that additionalProperties: false is not specified in json schemas
2 participants