Skip to content

Commit

Permalink
Exclude airbyte-cdk modules from schema discovery (#39586)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxi297 committed Jun 19, 2024
1 parent 69c0416 commit 0386ca2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _default_file_path() -> str:
# Schema files are always in "source_<connector_name>/schemas/<stream_name>.json
# The connector's module name can be inferred by looking at the modules loaded and look for the one starting with source_
source_modules = [
k for k, v in sys.modules.items() if "source_" in k
k for k, v in sys.modules.items() if "source_" in k and "airbyte_cdk" not in k
] # example: ['source_exchange_rates', 'source_exchange_rates.source']
if source_modules:
module = source_modules[0].split(".")[0]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
from unittest.mock import patch

import pytest
from airbyte_cdk.sources.declarative.schema import JsonFileSchemaLoader
from airbyte_cdk.sources.declarative.schema.json_file_schema_loader import JsonFileSchemaLoader, _default_file_path


@pytest.mark.parametrize(
Expand All @@ -24,3 +25,13 @@ def test_extract_resource_and_schema_path(test_name, input_path, expected_resour

assert actual_resource == expected_resource
assert actual_path == expected_path


@patch("airbyte_cdk.sources.declarative.schema.json_file_schema_loader.sys")
def test_exclude_cdk_packages(mocked_sys):
keys = ["airbyte_cdk.sources.concurrent_source.concurrent_source_adapter", "source_gitlab.utils"]
mocked_sys.modules = {key: "" for key in keys}

default_file_path = _default_file_path()

assert "source_gitlab" in default_file_path

0 comments on commit 0386ca2

Please sign in to comment.