# Buggy code
def check_client_version(self, client_type):
    # Ensure Azure modules are at least 2.0.0rc5.
    package_version = AZURE_PKG_VERSIONS.get(client_type.__name__, None)
    if package_version is not None:
        client_name = package_version.get("package_name")
        try:
            client_module = importlib.import_module(client_type.__module__)
            client_version = client_module.VERSION
        except RuntimeError:
            # can't get at the module version for some reason, just fail silently...
            return
        expected_version = package_version.get("expected_version")
        if Version(client_version) < Version(expected_version):
            self.fail(
                "Installed azure-mgmt-{0} client version is {1}. The minimum supported version is {2}. Try "
                "`pip install ansible[azure]`".format(
                    client_name, client_version, expected_version
                )
            )
        if Version(client_version) != Version(expected_version):
            self.module.warn(
                "Installed azure-mgmt-{0} client version is {1}. The expected version is {2}. Try "
                "`pip install ansible[azure]`".format(
                    client_name, client_version, expected_version
                )
            )


# Traceback (AttributeError)
/home/carbolymer/.ansible/tmp/ansible-tmp-1563194101.4601269-231050839847559/AnsiballZ_azure_rm_resourcegroup.py:18: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
Traceback (most recent call last):
File \"/home/carbolymer/.ansible/tmp/ansible-tmp-1563194101.4601269-231050839847559/AnsiballZ_azure_rm_resourcegroup.py\", line 114, in <module>
_ansiballz_main()
File \"/home/carbolymer/.ansible/tmp/ansible-tmp-1563194101.4601269-231050839847559/AnsiballZ_azure_rm_resourcegroup.py\", line 106, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File \"/home/carbolymer/.ansible/tmp/ansible-tmp-1563194101.4601269-231050839847559/AnsiballZ_azure_rm_resourcegroup.py\", line 49, in invoke_module
imp.load_module('__main__', mod, module, MOD_DESC)
File \"/usr/lib/python3.7/imp.py\", line 234, in load_module
return load_source(name, filename, file)
File \"/usr/lib/python3.7/imp.py\", line 169, in load_source
module = _exec(spec, sys.modules[name])
File \"<frozen importlib._bootstrap>\", line 630, in _exec
File \"<frozen importlib._bootstrap_external>\", line 728, in exec_module
File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed
File \"/tmp/ansible_azure_rm_resourcegroup_payload_uma4tka4/__main__.py\", line 266, in <module>
File \"/tmp/ansible_azure_rm_resourcegroup_payload_uma4tka4/__main__.py\", line 262, in main
File \"/tmp/ansible_azure_rm_resourcegroup_payload_uma4tka4/__main__.py\", line 144, in __init__
File \"/tmp/ansible_azure_rm_resourcegroup_payload_uma4tka4/ansible_azure_rm_resourcegroup_payload.zip/ansible/module_utils/azure_rm_common.py\", line 325, in __init__
File \"/tmp/ansible_azure_rm_resourcegroup_payload_uma4tka4/__main__.py\", line 158, in exec_module
File \"/tmp/ansible_azure_rm_resourcegroup_payload_uma4tka4/ansible_azure_rm_resourcegroup_payload.zip/ansible/module_utils/azure_rm_common.py\", line 831, in rm_client
File \"/tmp/ansible_azure_rm_resourcegroup_payload_uma4tka4/ansible_azure_rm_resourcegroup_payload.zip/ansible/module_utils/azure_rm_common.py\", line 729, in get_mgmt_svc_client
File \"/tmp/ansible_azure_rm_resourcegroup_payload_uma4tka4/ansible_azure_rm_resourcegroup_payload.zip/ansible/module_utils/azure_rm_common.py\", line 335, in check_client_version
AttributeError: module 'azure.mgmt.resource.resources._resource_management_client' has no attribute 'VERSION'

# Fixed code
def check_client_version(self, client_type):
    # Ensure Azure modules are at least 2.0.0rc5.
    package_version = AZURE_PKG_VERSIONS.get(client_type.__name__, None)
    if package_version is not None:
        client_name = package_version.get("package_name")
        try:
            client_module = importlib.import_module(client_type.__module__)
            client_version = client_module.VERSION
        except (RuntimeError, AttributeError):
            # can't get at the module version for some reason, just fail silently...
            return
        expected_version = package_version.get("expected_version")
        if Version(client_version) < Version(expected_version):
            self.fail(
                "Installed azure-mgmt-{0} client version is {1}. The minimum supported version is {2}. Try "
                "`pip install ansible[azure]`".format(
                    client_name, client_version, expected_version
                )
            )
        if Version(client_version) != Version(expected_version):
            self.module.warn(
                "Installed azure-mgmt-{0} client version is {1}. The expected version is {2}. Try "
                "`pip install ansible[azure]`".format(
                    client_name, client_version, expected_version
                )
            )