# Buggy code
def _deserialize(cls, encoded_var: Any) -> Any:  # pylint: disable=too-many-return-statements
    """Helper function of depth first search for deserialization."""
    # JSON primitives (except for dict) are not encoded.
    if cls._is_primitive(encoded_var):
        return encoded_var
    elif isinstance(encoded_var, list):
        return [cls._deserialize(v) for v in encoded_var]

    if not isinstance(encoded_var, dict):
        raise ValueError(f"The encoded_var should be dict and is {type(encoded_var)}")
    var = encoded_var[Encoding.VAR]
    type_ = encoded_var[Encoding.TYPE]

    if type_ == DAT.DICT:
        return {k: cls._deserialize(v) for k, v in var.items()}
    elif type_ == DAT.DAG:
        return SerializedDAG.deserialize_dag(var)
    elif type_ == DAT.OP:
        return SerializedBaseOperator.deserialize_operator(var)
    elif type_ == DAT.DATETIME:
        return pendulum.from_timestamp(var)
    elif type_ == DAT.POD:
        pod = PodGenerator.deserialize_model_dict(var)
        return pod
    elif type_ == DAT.TIMEDELTA:
        return datetime.timedelta(seconds=var)
    elif type_ == DAT.TIMEZONE:
        return Timezone(var)
    elif type_ == DAT.RELATIVEDELTA:
        if "weekday" in var:
            var["weekday"] = relativedelta.weekday(*var["weekday"])  # type: ignore
        return relativedelta.relativedelta(**var)
    elif type_ == DAT.SET:
        return {cls._deserialize(v) for v in var}
    elif type_ == DAT.TUPLE:
        return tuple([cls._deserialize(v) for v in var])
    else:
        raise TypeError("Invalid type {!s} in deserialization.".format(type_))


# Traceback (ModuleNotFoundError)
$ airflow db check
Traceback (most recent call last):
File "/.../bin/airflow", line 8, in <module>
sys.exit(main())
File "/.../lib/python3.6/site-packages/airflow/__main__.py", line 40, in main
args.func(args)
File "/.../lib/python3.6/site-packages/airflow/cli/cli_parser.py", line 52, in command
func = import_string(import_path)
File "/.../lib/python3.6/site-packages/airflow/utils/module_loading.py", line 32, in import_string
module = import_module(module_path)
File "/.../lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/.../lib/python3.6/site-packages/airflow/cli/commands/db_command.py", line 24, in <module>
from airflow.utils import cli as cli_utils, db
File "/.../lib/python3.6/site-packages/airflow/utils/db.py", line 26, in <module>
from airflow.jobs.base_job import BaseJob  # noqa: F401 # pylint: disable=unused-import
File "/.../lib/python3.6/site-packages/airflow/jobs/__init__.py", line 22, in <module>
import airflow.jobs.scheduler_job  # noqa
File "/.../lib/python3.6/site-packages/airflow/jobs/scheduler_job.py", line 50, in <module>
from airflow.models.serialized_dag import SerializedDagModel
File "/.../lib/python3.6/site-packages/airflow/models/serialized_dag.py", line 35, in <module>
from airflow.serialization.serialized_objects import SerializedDAG
File "/.../lib/python3.6/site-packages/airflow/serialization/serialized_objects.py", line 37, in <module>
from airflow.kubernetes.pod_generator import PodGenerator
File "/.../lib/python3.6/site-packages/airflow/kubernetes/pod_generator.py", line 35, in <module>
from kubernetes.client import models as k8s
ModuleNotFoundError: No module named 'kubernetes'

# Fixed code
def _deserialize(cls, encoded_var: Any) -> Any:  # pylint: disable=too-many-return-statements
    """Helper function of depth first search for deserialization."""
    # JSON primitives (except for dict) are not encoded.
    if cls._is_primitive(encoded_var):
        return encoded_var
    elif isinstance(encoded_var, list):
        return [cls._deserialize(v) for v in encoded_var]

    if not isinstance(encoded_var, dict):
        raise ValueError(f"The encoded_var should be dict and is {type(encoded_var)}")
    var = encoded_var[Encoding.VAR]
    type_ = encoded_var[Encoding.TYPE]

    if type_ == DAT.DICT:
        return {k: cls._deserialize(v) for k, v in var.items()}
    elif type_ == DAT.DAG:
        return SerializedDAG.deserialize_dag(var)
    elif type_ == DAT.OP:
        return SerializedBaseOperator.deserialize_operator(var)
    elif type_ == DAT.DATETIME:
        return pendulum.from_timestamp(var)
    elif type_ == DAT.POD:
        if not HAS_KUBERNETES:
            raise RuntimeError(
                "Cannot deserialize POD objects without kubernetes libraries installed!"
            )
        pod = PodGenerator.deserialize_model_dict(var)
        return pod
    elif type_ == DAT.TIMEDELTA:
        return datetime.timedelta(seconds=var)
    elif type_ == DAT.TIMEZONE:
        return Timezone(var)
    elif type_ == DAT.RELATIVEDELTA:
        if "weekday" in var:
            var["weekday"] = relativedelta.weekday(*var["weekday"])  # type: ignore
        return relativedelta.relativedelta(**var)
    elif type_ == DAT.SET:
        return {cls._deserialize(v) for v in var}
    elif type_ == DAT.TUPLE:
        return tuple([cls._deserialize(v) for v in var])
    else:
        raise TypeError("Invalid type {!s} in deserialization.".format(type_))