|
5 | 5 | import inspect |
6 | 6 | from collections.abc import Callable |
7 | 7 | from dataclasses import dataclass |
8 | | -from importlib import import_module |
9 | 8 | from typing import Any, Dict, Iterable, Optional, Type |
10 | 9 |
|
11 | | -from haystack.core.component.component import _hook_component_init, logger |
| 10 | +from haystack import logging |
| 11 | +from haystack.core.component.component import _hook_component_init |
12 | 12 | from haystack.core.errors import DeserializationError, SerializationError |
| 13 | +from haystack.utils.type_serialization import thread_safe_import |
| 14 | + |
| 15 | +logger = logging.getLogger(__name__) |
13 | 16 |
|
14 | 17 |
|
15 | 18 | @dataclass(frozen=True) |
@@ -251,9 +254,11 @@ def import_class_by_name(fully_qualified_name: str) -> Type[object]: |
251 | 254 | """ |
252 | 255 | try: |
253 | 256 | module_path, class_name = fully_qualified_name.rsplit(".", 1) |
254 | | - logger.debug(f"Attempting to import class '{class_name}' from module '{module_path}'") |
255 | | - module = import_module(module_path) |
| 257 | + logger.debug( |
| 258 | + "Attempting to import class '{cls_name}' from module '{md_path}'", cls_name=class_name, md_path=module_path |
| 259 | + ) |
| 260 | + module = thread_safe_import(module_path) |
256 | 261 | return getattr(module, class_name) |
257 | 262 | except (ImportError, AttributeError) as error: |
258 | | - logger.error(f"Failed to import class '{fully_qualified_name}'") |
| 263 | + logger.error("Failed to import class '{full_name}'", full_name=fully_qualified_name) |
259 | 264 | raise ImportError(f"Could not import class '{fully_qualified_name}'") from error |
0 commit comments