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

Source Klaviyo: update schema validation in SAT #6952

Merged
merged 7 commits into from
Oct 21, 2021

Conversation

gaart
Copy link
Contributor

@gaart gaart commented Oct 11, 2021

What

Fix #6815

How

There's a test which checks response schemas. Some fields can be optional (null value). Usually we mark them like ["null", "string"]. In this connector we use pydantic which generates invalid type, e.g. for name: Optional[str] we expect to have

{
"title": "Name",
"type": ["null", "string"]
}

but get

{
"title": "Name" ,
"type": "string"
}

We can skip the schema validation test since pydantic does the same during response processing and the test will fail anyway if schema is wrong.

Pre-merge Checklist

Expand the relevant checklist and delete the others.

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions
  • Connector version bumped like described here

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here

@github-actions github-actions bot added the area/connectors Connector related issues label Oct 11, 2021
@gaart gaart requested a review from sherifnada October 12, 2021 06:30
@keu keu self-requested a review October 12, 2021 06:35
@keu
Copy link
Contributor

keu commented Oct 12, 2021

@gaart I don't think I understand why disable check is the best fix here, could you add more details?

@davinchia
Copy link
Contributor

How does this fix the build?

@gaart
Copy link
Contributor Author

gaart commented Oct 12, 2021

@keu @davinchia
There's a test which checks response schemas. Some fields can be optional (null value). Usually we mark them like ["null", "string"]. In this connector we use pydantic which generates invalid type, e.g. for name: Optional[str] we expect to have

{
"title": "Name",
"type": ["null", "string"]
}

but get

{
"title": "Name" ,
"type": "string"
}

We can skip the schema validation test since pydantic does the same during response processing and the test will fail anyway if schema is wrong

@gaart
Copy link
Contributor Author

gaart commented Oct 12, 2021

/test connector=connectors/source-klaviyo

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

	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                                 Stmts   Miss  Cover
	 ------------------------------------------------------------------------
	 source_acceptance_test/__init__.py                       2      0   100%
	 source_acceptance_test/base.py                          10      4    60%
	 source_acceptance_test/config.py                        74      8    89%
	 source_acceptance_test/conftest.py                     108    108     0%
	 source_acceptance_test/plugin.py                        47     47     0%
	 source_acceptance_test/tests/__init__.py                 4      0   100%
	 source_acceptance_test/tests/test_core.py              200     94    53%
	 source_acceptance_test/tests/test_full_refresh.py       18     11    39%
	 source_acceptance_test/tests/test_incremental.py        69     38    45%
	 source_acceptance_test/utils/__init__.py                 6      0   100%
	 source_acceptance_test/utils/asserts.py                 37      2    95%
	 source_acceptance_test/utils/common.py                  41     24    41%
	 source_acceptance_test/utils/compare.py                 47     20    57%
	 source_acceptance_test/utils/connector_runner.py        82     49    40%
	 source_acceptance_test/utils/json_schema_helper.py     115     14    88%
	 ------------------------------------------------------------------------
	 TOTAL                                                  860    419    51%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                         Stmts   Miss  Cover
	 ------------------------------------------------
	 source_klaviyo/__init__.py       2      2     0%
	 source_klaviyo/schemas.py       62     62     0%
	 source_klaviyo/source.py        28     28     0%
	 source_klaviyo/streams.py       77     77     0%
	 ------------------------------------------------
	 ------------------------------------------------/actions-runner/_work/airbyte/airbyte/airbyte-integrations/connectors/source-klaviyo/.venv/lib/python3.8/site-packages/coverage/control.py:761: CoverageWarning: No data was collected. (no-data-collected)
	 TOTAL                          169    169     0%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                         Stmts   Miss  Cover
	 ------------------------------------------------
	 source_klaviyo/__init__.py       2      2     0%
	 Name                         Stmts   Miss  Cover/actions-runner/_work/airbyte/airbyte/airbyte-integrations/connectors/source-klaviyo/.venv/lib/python3.8/site-packages/coverage/control.py:761: CoverageWarning: No data was collected. (no-data-collected)
	 source_klaviyo/schemas.py       62     62     0%
	 source_klaviyo/source.py        28     28     0%
	 source_klaviyo/streams.py       77     77     0%
	 ------------------------------------------------
	 TOTAL                          169    169     0%

@jrhizor jrhizor temporarily deployed to more-secrets October 12, 2021 13:30 Inactive
@keu
Copy link
Contributor

keu commented Oct 12, 2021

@keu @davinchia There's a test which checks response schemas. Some fields can be optional (null value). Usually we mark them like ["null", "string"]. In this connector we use pydantic which generates invalid type, e.g. for name: Optional[str] we expect to have

{
"title": "Name",
"type": ["null", "string"]
}

but get

{
"title": "Name" ,
"type": "string"
}

We can skip the schema validation test since pydantic does the same during response processing and the test will fail anyway if schema is wrong

@gaart I see.
In some places where we use pydantic we have the following code in the base model class:

        @classmethod
        def schema_extra(cls, schema: Dict[str, Any], model: Type["BaseModel"]) -> None:
            schema.pop("title", None)
            schema.pop("description", None)
            for name, prop in schema.get("properties", {}).items():
                prop.pop("title", None)
                prop.pop("description", None)
                allow_none = model.__fields__[name].allow_none
                if allow_none:
                    if "type" in prop:
                        prop["type"] = ["null", prop["type"]]
                    elif "$ref" in prop:
                        ref = prop.pop("$ref")
                        prop["oneOf"] = [{"type": "null"}, {"$ref": ref}]

this will produce the expected schema.
Although I think that pydantic validation is good, I see few downsides:

  • performance
  • validation of pydantic model and json_schema could be different as we see here.

@sherifnada what do you think, should we keep pydantic validation during the read in the connector code?

@keu
Copy link
Contributor

keu commented Oct 12, 2021

also, the details aboive should be in the ticket itself, and the actual fix should be reflected in the PR title (i.e. Klaviyo: disable schema validation in SAT).

@gaart gaart changed the title Source Klaviyo: Fix connector build Source Klaviyo: disable schema validation in SAT Oct 12, 2021
@davinchia
Copy link
Contributor

This feels like we should fix the base model and not disable the validation or it will get confusing if we have many connectors doing this differently. I will defer to Sherif.

@sherifnada
Copy link
Contributor

I agree with Davin. Disabling schema validation would be throwing out the baby with the bathwater

@gaart gaart temporarily deployed to more-secrets October 13, 2021 19:33 Inactive
@gaart
Copy link
Contributor Author

gaart commented Oct 13, 2021

/test connector=connectors/source-klaviyo

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

	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                                 Stmts   Miss  Cover
	 ------------------------------------------------------------------------
	 source_acceptance_test/__init__.py                       2      0   100%
	 source_acceptance_test/base.py                          10      4    60%
	 source_acceptance_test/config.py                        74      8    89%
	 source_acceptance_test/conftest.py                     108    108     0%
	 source_acceptance_test/plugin.py                        47     47     0%
	 source_acceptance_test/tests/__init__.py                 4      0   100%
	 source_acceptance_test/tests/test_core.py              200     94    53%
	 source_acceptance_test/tests/test_full_refresh.py       18     11    39%
	 source_acceptance_test/tests/test_incremental.py        69     38    45%
	 source_acceptance_test/utils/__init__.py                 6      0   100%
	 source_acceptance_test/utils/asserts.py                 37      2    95%
	 source_acceptance_test/utils/common.py                  41     24    41%
	 source_acceptance_test/utils/compare.py                 47     20    57%
	 source_acceptance_test/utils/connector_runner.py        82     49    40%
	 source_acceptance_test/utils/json_schema_helper.py     115     14    88%
	 ------------------------------------------------------------------------
	 TOTAL                                                  860    419    51%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                         Stmts   Miss  Cover
	 ------------------------------------------------
	 source_klaviyo/__init__.py       2      2     0%
	 source_klaviyo/schemas.py       72     72     0%
	 source_klaviyo/source.py        28     28     0%
	 source_klaviyo/streams.py       77     77     0%
	 ------------------------------------------------
	 TOTAL                          179    179     0%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                         Stmts   Miss  Cover
	 ------------------------------------------------
	 source_klaviyo/__init__.py       2      2     0%
	 source_klaviyo/schemas.py       72     72     0%
	 source_klaviyo/source.py        28     28     0%
	 source_klaviyo/streams.py       77     77     0%
	 ------------------------------------------------
	 TOTAL                          179    179     0%

@jrhizor jrhizor temporarily deployed to more-secrets October 13, 2021 19:36 Inactive
@gaart
Copy link
Contributor Author

gaart commented Oct 13, 2021

@keu @davinchia @sherifnada updated

prop.pop("title", None)
prop.pop("description", None)
allow_none = model.__fields__[name].allow_none
Copy link
Contributor

Choose a reason for hiding this comment

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

this should have a comment describing what is happening

@gaart gaart changed the title Source Klaviyo: disable schema validation in SAT Source Klaviyo: update schema validation in SAT Oct 14, 2021
@gaart gaart temporarily deployed to more-secrets October 18, 2021 15:39 Inactive
@gaart
Copy link
Contributor Author

gaart commented Oct 19, 2021

/test connector=connectors/source-klaviyo

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

	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                                 Stmts   Miss  Cover
	 ------------------------------------------------------------------------
	 source_acceptance_test/__init__.py                       2      0   100%
	 source_acceptance_test/base.py                          10      4    60%
	 source_acceptance_test/config.py                        74      8    89%
	 source_acceptance_test/conftest.py                     108    108     0%
	 source_acceptance_test/plugin.py                        47     47     0%
	 source_acceptance_test/tests/__init__.py                 4      0   100%
	 source_acceptance_test/tests/test_core.py              200     94    53%
	 source_acceptance_test/tests/test_full_refresh.py       18     11    39%
	 source_acceptance_test/tests/test_incremental.py        69     38    45%
	 source_acceptance_test/utils/__init__.py                 6      0   100%
	 source_acceptance_test/utils/asserts.py                 37      2    95%
	 source_acceptance_test/utils/common.py                  41     24    41%
	 source_acceptance_test/utils/compare.py                 47     20    57%
	 source_acceptance_test/utils/connector_runner.py        82     49    40%
	 source_acceptance_test/utils/json_schema_helper.py     115     14    88%
	 ------------------------------------------------------------------------
	 TOTAL                                                  860    419    51%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                         Stmts   Miss  Cover
	 ------------------------------------------------
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 source_klaviyo/__init__.py       2      2     0%
	 source_klaviyo/schemas.py       70     70     0%
	   self._warn("No data was collected.", slug="no-data-collected")
	 source_klaviyo/source.py        28     28     0%
	 source_klaviyo/streams.py       77     77     0%
	 ------------------------------------------------
	 TOTAL                          177    177     0%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                         Stmts   Miss  Cover
	 ------------------------------------------------
	 unit_tests/unit_test.py::test_example_method �[32mPASSED�[0m/actions-runner/_work/airbyte/airbyte/airbyte-integrations/connectors/source-klaviyo/.venv/lib/python3.8/site-packages/coverage/control.py:761: CoverageWarning: No data was collected. (no-data-collected)
	 source_klaviyo/__init__.py       2      2     0%
	 source_klaviyo/schemas.py       70     70     0%
	 source_klaviyo/source.py        28     28     0%
	 source_klaviyo/streams.py       77     77     0%
	 ------------------------------------------------
	 TOTAL                          177    177     0%

@jrhizor jrhizor temporarily deployed to more-secrets October 19, 2021 13:48 Inactive
@github-actions github-actions bot added the area/documentation Improvements or additions to documentation label Oct 19, 2021
@gaart
Copy link
Contributor Author

gaart commented Oct 19, 2021

/publish connector=connectors/source-klaviyo

🕑 connectors/source-klaviyo https://github.com/airbytehq/airbyte/actions/runs/1359666981
❌ connectors/source-klaviyo https://github.com/airbytehq/airbyte/actions/runs/1359666981

@gaart gaart temporarily deployed to more-secrets October 19, 2021 14:47 Inactive
@jrhizor jrhizor temporarily deployed to more-secrets October 19, 2021 14:47 Inactive
@gaart
Copy link
Contributor Author

gaart commented Oct 19, 2021

/publish connector=connectors/source-klaviyo

🕑 connectors/source-klaviyo https://github.com/airbytehq/airbyte/actions/runs/1359697051
❌ connectors/source-klaviyo https://github.com/airbytehq/airbyte/actions/runs/1359697051

@jrhizor jrhizor temporarily deployed to more-secrets October 19, 2021 14:55 Inactive
@gaart
Copy link
Contributor Author

gaart commented Oct 19, 2021

/test connector=connectors/source-klaviyo

🕑 connectors/source-klaviyo https://github.com/airbytehq/airbyte/actions/runs/1359725592
❌ connectors/source-klaviyo https://github.com/airbytehq/airbyte/actions/runs/1359725592
🐛

@jrhizor jrhizor temporarily deployed to more-secrets October 19, 2021 15:02 Inactive
@gaart
Copy link
Contributor Author

gaart commented Oct 20, 2021

/test connector=connectors/source-klaviyo

🕑 connectors/source-klaviyo https://github.com/airbytehq/airbyte/actions/runs/1365097072
❌ connectors/source-klaviyo https://github.com/airbytehq/airbyte/actions/runs/1365097072
🐛

@jrhizor jrhizor temporarily deployed to more-secrets October 20, 2021 19:49 Inactive
@sherifnada
Copy link
Contributor

@gaart pulling master should fix the issue

@gaart
Copy link
Contributor Author

gaart commented Oct 21, 2021

/test connector=connectors/source-klaviyo

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

	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                                 Stmts   Miss  Cover
	 ------------------------------------------------------------------------
	 source_acceptance_test/__init__.py                       2      0   100%
	 source_acceptance_test/base.py                          10      4    60%
	 source_acceptance_test/config.py                        74      8    89%
	 source_acceptance_test/conftest.py                     108    108     0%
	 source_acceptance_test/plugin.py                        47     47     0%
	 source_acceptance_test/tests/__init__.py                 4      0   100%
	 source_acceptance_test/tests/test_core.py              200     94    53%
	 source_acceptance_test/tests/test_full_refresh.py       18     11    39%
	 source_acceptance_test/tests/test_incremental.py        69     38    45%
	 source_acceptance_test/utils/__init__.py                 6      0   100%
	 source_acceptance_test/utils/asserts.py                 37      2    95%
	 source_acceptance_test/utils/common.py                  41     24    41%
	 source_acceptance_test/utils/compare.py                 47     20    57%
	 source_acceptance_test/utils/connector_runner.py        82     49    40%
	 source_acceptance_test/utils/json_schema_helper.py     115     14    88%
	 ------------------------------------------------------------------------
	 TOTAL                                                  860    419    51%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                         Stmts   Miss  Cover
	 ------------------------------------------------
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------/actions-runner/_work/airbyte/airbyte/airbyte-integrations/connectors/source-klaviyo/.venv/lib/python3.8/site-packages/coverage/control.py:761: CoverageWarning: No data was collected. (no-data-collected)
	 source_klaviyo/__init__.py       2      2     0%
	   self._warn("No data was collected.", slug="no-data-collected")
	 source_klaviyo/schemas.py       70     70     0%
	 source_klaviyo/source.py        28     28     0%
	 source_klaviyo/streams.py       77     77     0%
	 ------------------------------------------------
	 TOTAL                          177    177     0%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                         Stmts   Miss  Cover
	 ------------------------------------------------
	 source_klaviyo/__init__.py       2      2     0%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------/actions-runner/_work/airbyte/airbyte/airbyte-integrations/connectors/source-klaviyo/.venv/lib/python3.8/site-packages/coverage/control.py:761: CoverageWarning: No data was collected. (no-data-collected)
	 source_klaviyo/schemas.py       70     70     0%
	 source_klaviyo/source.py        28     28     0%
	 source_klaviyo/streams.py       77     77     0%
	 ------------------------------------------------
	   self._warn("No data was collected.", slug="no-data-collected")
	 TOTAL                          177    177     0%

@gaart gaart temporarily deployed to more-secrets October 21, 2021 09:39 Inactive
@jrhizor jrhizor temporarily deployed to more-secrets October 21, 2021 09:42 Inactive
@gaart
Copy link
Contributor Author

gaart commented Oct 21, 2021

/publish connector=connectors/source-klaviyo

🕑 connectors/source-klaviyo https://github.com/airbytehq/airbyte/actions/runs/1367353184
✅ connectors/source-klaviyo https://github.com/airbytehq/airbyte/actions/runs/1367353184

@jrhizor jrhizor temporarily deployed to more-secrets October 21, 2021 09:48 Inactive
@gaart gaart merged commit dfdbda8 into master Oct 21, 2021
@gaart gaart deleted the gaart/6815-source-klaviyo-fix-build branch October 21, 2021 10:05
schlattk pushed a commit to schlattk/airbyte that referenced this pull request Jan 4, 2022
* Disable schema validation for configured_catalog

* Upd pydantic-generated schema

* Upd comment

* Bump version, upd changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/connectors Connector related issues area/documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix klaviyo source connectro build
5 participants