From 0386ca21ae1322b7e6c49858ab2525bb301467f7 Mon Sep 17 00:00:00 2001 From: Maxime Carbonneau-Leclerc <3360483+maxi297@users.noreply.github.com> Date: Wed, 19 Jun 2024 09:29:45 -0400 Subject: [PATCH] Exclude airbyte-cdk modules from schema discovery (#39586) --- .../declarative/schema/json_file_schema_loader.py | 2 +- .../schema/test_json_file_schema_loader.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/airbyte-cdk/python/airbyte_cdk/sources/declarative/schema/json_file_schema_loader.py b/airbyte-cdk/python/airbyte_cdk/sources/declarative/schema/json_file_schema_loader.py index bfadbe8f9f080d..af51fe5db01e0a 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/declarative/schema/json_file_schema_loader.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/declarative/schema/json_file_schema_loader.py @@ -18,7 +18,7 @@ def _default_file_path() -> str: # Schema files are always in "source_/schemas/.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] diff --git a/airbyte-cdk/python/unit_tests/sources/declarative/schema/test_json_file_schema_loader.py b/airbyte-cdk/python/unit_tests/sources/declarative/schema/test_json_file_schema_loader.py index aa2f99b48901b2..8ef467618634ee 100644 --- a/airbyte-cdk/python/unit_tests/sources/declarative/schema/test_json_file_schema_loader.py +++ b/airbyte-cdk/python/unit_tests/sources/declarative/schema/test_json_file_schema_loader.py @@ -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( @@ -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