Skip to content

Commit ce1074b

Browse files
authored
Fix(sdm): module ref issue in python components import (#243)
1 parent 3a9ab87 commit ce1074b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import annotations
66

77
import datetime
8+
import importlib
89
import inspect
910
import re
1011
import sys
@@ -1180,14 +1181,17 @@ def _get_class_from_fully_qualified_class_name(
11801181
module_name_full = ".".join(split[:-1])
11811182
class_name = split[-1]
11821183

1183-
if module_name_full == COMPONENTS_MODULE_NAME:
1184-
# Assume "components" on its own means "source_declarative_manifest.components"
1185-
module_name_full = SDM_COMPONENTS_MODULE_NAME
1184+
try:
1185+
module_ref = importlib.import_module(module_name_full)
1186+
except ModuleNotFoundError as e:
1187+
raise ValueError(f"Could not load module `{module_name_full}`.") from e
11861188

11871189
try:
1188-
return getattr(sys.modules[module_name_full], class_name)
1189-
except (AttributeError, ModuleNotFoundError) as e:
1190-
raise ValueError(f"Could not load class {full_qualified_class_name}.") from e
1190+
return getattr(module_ref, class_name)
1191+
except AttributeError as e:
1192+
raise ValueError(
1193+
f"Could not load class `{class_name}` from module `{module_name_full}`.",
1194+
) from e
11911195

11921196
@staticmethod
11931197
def _derive_component_type_from_type_hints(field_type: Any) -> Optional[str]:

0 commit comments

Comments
 (0)