# Buggy code
def _check_missing_providers(providers):
    current_airflow_version = Version(__import__("airflow").__version__)
    if current_airflow_version.major >= 2:
        prefix = "apache-airflow-providers-"
    else:
        prefix = "apache-airflow-backport-providers-"

    for provider in providers:
        dist_name = prefix + provider
        try:
            distribution(dist_name)
        except PackageNotFoundError:
            yield "Please install `{}`".format(dist_name)


# Traceback (AttributeError)
airflow@staging-airflow1:~$ airflow upgrade_check --config upgrade.yml
Using config file: upgrade.yml

=========================================================================================== STATUS ==========================================================================================

Check for latest versions of apache-airflow and checker............................................................................................................................FAIL
Remove airflow.AirflowMacroPlugin class............................................................................................................................................SUCCESS
Ensure users are not using custom metaclasses in custom operators..................................................................................................................SUCCESS
Chain between DAG and operator not allowed.........................................................................................................................................SUCCESS
Connection.conn_type is not nullable...............................................................................................................................................SUCCESS
Custom Executors now require full path.............................................................................................................................................SUCCESS
Hooks that run DB functions must inherit from DBApiHook............................................................................................................................FAIL
Fernet is enabled by default.......................................................................................................................................................SUCCESS
GCP service account key deprecation................................................................................................................................................SUCCESS
Unify hostname_callable option in core section.....................................................................................................................................SUCCESS
Traceback (most recent call last):
File "/usr/local/bin/airflow", line 37, in <module>
args.func(args)
File "/usr/local/lib/python3.6/dist-packages/airflow/upgrade/checker.py", line 118, in run
all_problems = check_upgrade(formatter, rules)
File "/usr/local/lib/python3.6/dist-packages/airflow/upgrade/checker.py", line 38, in check_upgrade
rule_status = RuleStatus.from_rule(rule)
File "/usr/local/lib/python3.6/dist-packages/airflow/upgrade/problem.py", line 48, in from_rule
messages = list(result)
File "/usr/local/lib/python3.6/dist-packages/airflow/upgrade/rules/import_changes.py", line 126, in _check_missing_providers
if current_airflow_version.major >= 2:
AttributeError: 'Version' object has no attribute 'major'

# Fixed code
def _check_missing_providers(providers):
    current_airflow_version = Version(__import__("airflow").__version__)
    if current_airflow_version >= Version("2.0.0"):
        prefix = "apache-airflow-providers-"
    else:
        prefix = "apache-airflow-backport-providers-"

    for provider in providers:
        dist_name = prefix + provider
        try:
            distribution(dist_name)
        except PackageNotFoundError:
            yield "Please install `{}`".format(dist_name)