-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
4776: Python CDK: Validate input config.py against spec #5457
Conversation
bcc4dc6
to
257c9bb
Compare
257c9bb
to
c019bce
Compare
airbyte-cdk/python/CHANGELOG.md
Outdated
@@ -1,5 +1,11 @@ | |||
# Changelog | |||
|
|||
## 0.1.10 | |||
Add checking specified config againt spec for read, write, check and ddiscover commands |
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.
Add checking specified config againt spec for read, write, check and ddiscover commands | |
Add checking specified config againt spec for read, write, check and discover commands |
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.
Updated
airbyte-cdk/python/CHANGELOG.md
Outdated
Add checking specified config againt spec for read, write, check and ddiscover commands | ||
|
||
##0.1.9 | ||
remove this line after rebase |
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.
rudiment?
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.
No, its cause Artur has his MR with 0.1.9 version published so my is 0.1.10 https://pypi.org/project/airbyte-cdk/
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'm waiting when he will be ready, rebase my changes onto his and update this file
spec_schema = spec.connectionSpecification | ||
try: | ||
validate(instance=config, schema=spec_schema) | ||
return None |
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.
return None | |
return |
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.
Updated
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.
Small changes
e4bdf9a
to
e3d5279
Compare
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.
couple of changes needed:
- exit code should be > 0 if config is invalid
- we should have unit tests for checkin catalogs #1
|
||
@abstractmethod | ||
def write( | ||
self, config: Mapping[str, Any], configured_catalog: ConfiguredAirbyteCatalog, input_messages: Iterable[AirbyteMessage] | ||
) -> Iterable[AirbyteMessage]: | ||
"""Implement to define how the connector writes data to the destination""" | ||
|
||
def _run_spec(self) -> AirbyteMessage: | ||
return AirbyteMessage(type=Type.SPEC, spec=self.spec(self.logger)) | ||
def _run_spec(self, spec: ConnectorSpecification) -> AirbyteMessage: |
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.
we should delete this method, calling it _run_spec
when it just wraps an object is misleading
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.
Fixed
airbyte-cdk/python/setup.py
Outdated
@@ -35,7 +35,7 @@ | |||
|
|||
setup( | |||
name="airbyte-cdk", | |||
version="0.1.8", | |||
version="0.1.10", |
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.
you'll need to either merge this with arthur's changes or release separately
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.
Ive merged Arthur's branch into mine so now this PR looks dirty before his branch will be merged on master.
return | ||
config = self.read_config(config_path=parsed_args.config) | ||
check_error_msg = check_config_against_spec(config, spec) | ||
if check_error_msg: |
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.
an invalid config should cause the exit code to be >0, it's invalid input. An exit code of 0 means the connector succeeded
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.
Updated
…h' into drezchykov/4776-cdk-validate-spec
Didnt get about this. Looks like an old PR with json files and bash scripts. How can I add unit tests on it? |
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.
Couple of comments, feel free to merge once they are addressed and the other PR is merged
@@ -180,6 +180,7 @@ def test_run_check(self, mocker, destination: Destination, tmp_path): | |||
parsed_args = argparse.Namespace(**args) | |||
destination.run_cmd(parsed_args) | |||
|
|||
mocker.patch.object(destination, "spec", return_value=ConnectorSpecification(connectionSpecification={})) |
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.
we should add a test case here too to verify the config is validated.
It may help to look at test coverage by running ./type_check_and_test.sh
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.
There is already detailed test case that covers validation function here: https://github.com/airbytehq/airbyte/pull/5457/files#diff-0d9087e19f5bdabe137529bb861aaaa261b39d5344e79041602a2a94c7530301R150 So Ive just added checks if this validation function is called with correct args for destination.
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.
Thanks, done
|
||
def check_config_against_spec_or_exit(config: Mapping[str, Any], spec: ConnectorSpecification, logger: Logger): | ||
""" | ||
Check config object against spec. In case of spec is invalid, throws |
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.
nice docstring
ebaa6aa
to
e29552e
Compare
What
Resolves #4776
How
Describe the solution
Recommended reading order
x.java
y.python
Pre-merge Checklist
Expand the relevant checklist and delete the others.
New Connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
docs/SUMMARY.md
docs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampledocs/integrations/README.md
airbyte-integrations/builds.md
Airbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing./publish
command described hereUpdating a connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
docs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampleAirbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing./publish
command described hereConnector Generator
-scaffold
in their name) have been updated with the latest scaffold by running./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates
then checking in your changes