fix(ingest): replace ImportError with ModuleNotFoundError (#2498)

Using the more specific exception will prevent us from accidentally
ignoring errors that should be handled.
This commit is contained in:
Harshal Sheth 2021-05-05 14:05:16 -07:00 committed by GitHub
parent b4457afe30
commit 7f0656fd5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 9 additions and 8 deletions

View File

@ -11,8 +11,9 @@ from airflow import DAG
try: try:
from airflow.operators.python import PythonOperator from airflow.operators.python import PythonOperator
except ImportError: except ModuleNotFoundError:
from airflow.operators.python_operator import PythonOperator from airflow.operators.python_operator import PythonOperator
from airflow.utils.dates import days_ago from airflow.utils.dates import days_ago
from datahub.ingestion.run.pipeline import Pipeline from datahub.ingestion.run.pipeline import Pipeline

View File

@ -10,7 +10,7 @@ from airflow.utils.dates import days_ago
try: try:
from airflow.operators.bash import BashOperator from airflow.operators.bash import BashOperator
except ImportError: except ModuleNotFoundError:
from airflow.operators.bash_operator import BashOperator from airflow.operators.bash_operator import BashOperator
from datahub.integrations.airflow.entities import Dataset from datahub.integrations.airflow.entities import Dataset

View File

@ -12,7 +12,7 @@ from airflow.utils.dates import days_ago
try: try:
from airflow.operators.python import PythonOperator from airflow.operators.python import PythonOperator
except ImportError: except ModuleNotFoundError:
from airflow.operators.python_operator import PythonOperator from airflow.operators.python_operator import PythonOperator
from datahub.ingestion.run.pipeline import Pipeline from datahub.ingestion.run.pipeline import Pipeline

View File

@ -54,7 +54,7 @@ class Registry(Generic[T]):
try: try:
plugin_class = entry_point.load() plugin_class = entry_point.load()
except ImportError as e: except ModuleNotFoundError as e:
self.register_disabled(name, e) self.register_disabled(name, e)
continue continue

View File

@ -2,6 +2,6 @@ try:
from datahub.integrations.airflow.lineage_backend import ( from datahub.integrations.airflow.lineage_backend import (
DatahubAirflowLineageBackend, DatahubAirflowLineageBackend,
) )
except ImportError: except ModuleNotFoundError:
# Compat for Airflow 2.x. # Compat for Airflow 2.x.
pass pass

View File

@ -6,7 +6,7 @@ try:
from airflow.hooks.base import BaseHook from airflow.hooks.base import BaseHook
AIRFLOW_1 = False AIRFLOW_1 = False
except ImportError: except ModuleNotFoundError:
from airflow.hooks.base_hook import BaseHook from airflow.hooks.base_hook import BaseHook
AIRFLOW_1 = True AIRFLOW_1 = True

View File

@ -14,7 +14,7 @@ from airflow.utils.dates import days_ago
try: try:
from airflow.operators.dummy import DummyOperator from airflow.operators.dummy import DummyOperator
except ImportError: except ModuleNotFoundError:
from airflow.operators.dummy_operator import DummyOperator from airflow.operators.dummy_operator import DummyOperator
import datahub.emitter.mce_builder as builder import datahub.emitter.mce_builder as builder

View File

@ -43,7 +43,7 @@ def test_registry():
# Make a mini sink registry. # Make a mini sink registry.
fake_registry = Registry[Sink]() fake_registry = Registry[Sink]()
fake_registry.register("console", ConsoleSink) fake_registry.register("console", ConsoleSink)
fake_registry.register_disabled("disabled", ImportError("disabled sink")) fake_registry.register_disabled("disabled", ModuleNotFoundError("disabled sink"))
class DummyClass: class DummyClass:
pass pass