-
Notifications
You must be signed in to change notification settings - Fork 25
feat: skip config validation during discovery for sources with DynamicSchemaLoader #467
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
Closed
aaronsteers
wants to merge
21
commits into
main
from
devin/1744215320-dynamic-schema-unprivileged-discovery-aj-author
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
cdd1ac9
feat: skip config validation during discovery for sources with Dynami…
devin-ai-integration[bot] 7490ad1
style: fix formatting issues
devin-ai-integration[bot] 9e84e1c
fix: update entrypoint to make --config optional for discovery
devin-ai-integration[bot] 47bd67c
style: fix formatting issues
devin-ai-integration[bot] 36d7f1f
fix: add type annotation for empty_config
devin-ai-integration[bot] b002218
refactor: use generator comprehension instead of list comprehension
devin-ai-integration[bot] acbab7e
Update airbyte_cdk/entrypoint.py
aaronsteers d33dcdd
Update CHANGELOG.md
aaronsteers 4253f28
Update airbyte_cdk/sources/declarative/manifest_declarative_source.py
aaronsteers 64610b9
feat: add check_config_during_discover flag for targeted config valid…
devin-ai-integration[bot] b228857
style: fix formatting issues
devin-ai-integration[bot] 77772c3
Update CHANGELOG.md
aaronsteers 6ca213c
refactor: push check_config_during_discover flag into connector base …
devin-ai-integration[bot] dce4f8c
style: fix formatting issues
devin-ai-integration[bot] 24a0919
fix: resolve MyPy type checking issues with check_config_during_disco…
devin-ai-integration[bot] f920f04
refactor: move check_config_during_discover to BaseConnector class
devin-ai-integration[bot] f01525f
Update airbyte_cdk/connector.py
aaronsteers 769d361
Update airbyte_cdk/connector.py
aaronsteers c3cbad8
Update airbyte_cdk/sources/declarative/manifest_declarative_source.py
aaronsteers 3cb8faf
Auto-fix lint and format issues
08397ad
fix condition direction
aaronsteers 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 hidden or 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 hidden or 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 hidden or 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
174 changes: 174 additions & 0 deletions
174
unit_tests/sources/declarative/test_manifest_declarative_source_dynamic_schema.py
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,174 @@ | ||
# | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
"""Tests for the ManifestDeclarativeSource with DynamicSchemaLoader.""" | ||
|
||
from unittest.mock import MagicMock, patch | ||
|
||
import pytest | ||
|
||
from airbyte_cdk.models import AirbyteCatalog | ||
from airbyte_cdk.sources.declarative.manifest_declarative_source import ManifestDeclarativeSource | ||
from airbyte_cdk.sources.utils.schema_helpers import check_config_against_spec_or_exit | ||
|
||
|
||
def test_check_config_during_discover_with_dynamic_schema_loader(): | ||
"""Test that check_config_during_discover is True when DynamicSchemaLoader is used.""" | ||
source_config = { | ||
"type": "DeclarativeSource", | ||
"check": {"type": "CheckStream"}, | ||
"streams": [ | ||
{ | ||
"name": "test_stream", | ||
"schema_loader": { | ||
"type": "DynamicSchemaLoader", | ||
"retriever": { | ||
"type": "SimpleRetriever", | ||
"requester": {"url_base": "https://example.com", "http_method": "GET"}, | ||
"record_selector": {"extractor": {"field_path": []}}, | ||
}, | ||
"schema_type_identifier": { | ||
"key_pointer": ["name"], | ||
}, | ||
}, | ||
"retriever": { | ||
"type": "SimpleRetriever", | ||
"requester": {"url_base": "https://example.com", "http_method": "GET"}, | ||
"record_selector": {"extractor": {"field_path": []}}, | ||
}, | ||
} | ||
], | ||
"version": "0.1.0", | ||
} | ||
|
||
source = ManifestDeclarativeSource(source_config=source_config) | ||
|
||
assert source.check_config_during_discover is True | ||
assert source.check_config_against_spec is True | ||
|
||
|
||
def test_check_config_during_discover_without_dynamic_schema_loader(): | ||
"""Test that check_config_during_discover is False when DynamicSchemaLoader is not used.""" | ||
source_config = { | ||
"type": "DeclarativeSource", | ||
"check": {"type": "CheckStream"}, | ||
"streams": [ | ||
{ | ||
"name": "test_stream", | ||
"schema_loader": {"type": "InlineSchemaLoader", "schema": {}}, | ||
"retriever": { | ||
"type": "SimpleRetriever", | ||
"requester": {"url_base": "https://example.com", "http_method": "GET"}, | ||
"record_selector": {"extractor": {"field_path": []}}, | ||
}, | ||
} | ||
], | ||
"version": "0.1.0", | ||
} | ||
|
||
source = ManifestDeclarativeSource(source_config=source_config) | ||
|
||
assert source.check_config_during_discover is False | ||
assert source.check_config_against_spec is True | ||
|
||
|
||
@patch( | ||
"airbyte_cdk.sources.declarative.manifest_declarative_source.ManifestDeclarativeSource.streams" | ||
) | ||
def test_discover_with_dynamic_schema_loader_no_config(mock_streams): | ||
"""Test that discovery works without config when DynamicSchemaLoader is used.""" | ||
mock_stream = MagicMock() | ||
mock_stream.name = "test_dynamic_stream" | ||
|
||
mock_airbyte_stream = MagicMock() | ||
type(mock_airbyte_stream).name = "test_dynamic_stream" | ||
mock_stream.as_airbyte_stream.return_value = mock_airbyte_stream | ||
|
||
mock_streams.return_value = [mock_stream] | ||
|
||
source_config = { | ||
"type": "DeclarativeSource", | ||
"check": {"type": "CheckStream"}, | ||
"streams": [ | ||
{ | ||
"name": "test_dynamic_stream", | ||
"schema_loader": { | ||
"type": "DynamicSchemaLoader", | ||
"retriever": { | ||
"type": "SimpleRetriever", | ||
"requester": {"url_base": "https://example.com", "http_method": "GET"}, | ||
"record_selector": {"extractor": {"field_path": []}}, | ||
}, | ||
"schema_type_identifier": { | ||
"key_pointer": ["name"], | ||
}, | ||
}, | ||
"retriever": { | ||
"type": "SimpleRetriever", | ||
"requester": {"url_base": "https://example.com", "http_method": "GET"}, | ||
"record_selector": {"extractor": {"field_path": []}}, | ||
}, | ||
} | ||
], | ||
"version": "0.1.0", | ||
} | ||
|
||
source = ManifestDeclarativeSource(source_config=source_config) | ||
|
||
assert source.check_config_during_discover is True | ||
assert source.check_config_against_spec is True | ||
|
||
logger = MagicMock() | ||
catalog = source.discover(logger, {}) | ||
|
||
assert isinstance(catalog, AirbyteCatalog) | ||
assert len(catalog.streams) == 1 | ||
assert catalog.streams[0].name == "test_dynamic_stream" | ||
|
||
|
||
@patch( | ||
"airbyte_cdk.sources.declarative.manifest_declarative_source.ManifestDeclarativeSource.streams" | ||
) | ||
def test_discover_without_dynamic_schema_loader_no_config(mock_streams): | ||
"""Test that discovery validates config when DynamicSchemaLoader is not used.""" | ||
mock_stream = MagicMock() | ||
mock_stream.name = "test_static_stream" | ||
|
||
mock_airbyte_stream = MagicMock() | ||
type(mock_airbyte_stream).name = "test_static_stream" | ||
mock_stream.as_airbyte_stream.return_value = mock_airbyte_stream | ||
|
||
mock_streams.return_value = [mock_stream] | ||
|
||
source_config = { | ||
"type": "DeclarativeSource", | ||
"check": {"type": "CheckStream"}, | ||
"streams": [ | ||
{ | ||
"name": "test_static_stream", | ||
"schema_loader": {"type": "InlineSchemaLoader", "schema": {}}, | ||
"retriever": { | ||
"type": "SimpleRetriever", | ||
"requester": {"url_base": "https://example.com", "http_method": "GET"}, | ||
"record_selector": {"extractor": {"field_path": []}}, | ||
}, | ||
} | ||
], | ||
"version": "0.1.0", | ||
} | ||
|
||
source = ManifestDeclarativeSource(source_config=source_config) | ||
|
||
assert source.check_config_during_discover is False | ||
assert source.check_config_against_spec is True | ||
|
||
logger = MagicMock() | ||
catalog = source.discover(logger, {}) | ||
|
||
assert isinstance(catalog, AirbyteCatalog) | ||
assert len(catalog.streams) == 1 | ||
assert catalog.streams[0].name == "test_static_stream" | ||
|
||
assert source.check_config_during_discover is False | ||
assert source.check_config_against_spec is True |
This file contains hidden or 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
Oops, something went wrong.
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.
This should be failing. Probably failing to fail because we're mocking.