aubdiy edited a comment on issue #20709:
URL: https://github.com/apache/airflow/issues/20709#issuecomment-1006989926
i have 2 ideas:
first:
1.
`/usr/local/python3.8/lib/python3.8/site-packages/airflow/providers_manager.py`
line 142 `import_string(class_name)`
2. the function `import_string` in the
`/usr/local/python3.8/lib/python3.8/site-packages/airflow/utils/module_loading.py`
3.
`/usr/local/python3.8/lib/python3.8/site-packages/airflow/utils/module_loading.py`
line 32 ` module = import_module(module_path)` may throw `No module
xxx` exception, use 'try' protect this line code, and log error level
log.
second:
or add another class 'ImportException', replace the current
'ImportError',
modify
`/usr/local/python3.8/lib/python3.8/site-packages/airflow/utils/module_loading.py`
```
from importlib import import_module
def import_string(dotted_path):
"""
Import a dotted module path and return the attribute/class designated by
the
last name in the path. Raise ImportError if the import failed.
"""
try:
module_path, class_name = dotted_path.rsplit('.', 1)
except ValueError:
raise ImportException(f"{dotted_path} doesn't look like a module
path")
try:
module = import_module(module_path)
except ValueError:
raise ImportError(f"{dotted_path} doesn't look like a module path")
try:
return getattr(module, class_name)
except AttributeError:
raise ImportException(f'Module "{module_path}" does not define a
"{class_name}" attribute/class')
def as_importable_string(thing) -> str:
"""Convert an attribute/class to a string importable by
``import_string``."""
return f"{thing.__module__}.{thing.__name__}"
```
then in
`/usr/local/python3.8/lib/python3.8/site-packages/airflow/providers_manager.py`
line 142 `import_string(class_name)` ,
```
try:
import_string(class_name)
except ImportError as e:
# When there is an ImportError we turn it into debug warnings as
this is
# an expected case when only some providers are installed
log.error(
"Exception when importing '%s' from '%s' package: %s",
class_name,
provider_package,
e,
)
return False
except ImportException as e:
# When there is an ImportError we turn it into debug warnings as
this is
# an expected case when only some providers are installed
log.debug(
"Exception when importing '%s' from '%s' package: %s",
class_name,
provider_package,
e,
)
return False
```
whether it is feasible?
@potiuk
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]