# Buggy code
def check_remote_network_config(remote, local):
    if local.driver and remote.get("Driver") != local.driver:
        raise NetworkConfigChangedError(local.true_name, "driver")
    local_opts = local.driver_opts or {}
    remote_opts = remote.get("Options") or {}
    for k in set.union(set(remote_opts.keys()), set(local_opts.keys())):
        if k in OPTS_EXCEPTIONS:
            continue
        if remote_opts.get(k) != local_opts.get(k):
            raise NetworkConfigChangedError(local.true_name, 'option "{}"'.format(k))

    if local.ipam is not None:
        check_remote_ipam_config(remote, local)

    if local.internal is not None and local.internal != remote.get("Internal", False):
        raise NetworkConfigChangedError(local.true_name, "internal")
    if local.enable_ipv6 is not None and local.enable_ipv6 != remote.get(
        "EnableIPv6", False
    ):
        raise NetworkConfigChangedError(local.true_name, "enable_ipv6")

    local_labels = local.labels or {}
    remote_labels = remote.get("Labels", {})
    for k in set.union(set(remote_labels.keys()), set(local_labels.keys())):
        if k.startswith(
            "com.docker."
        ):  # We are only interested in user-specified labels
            continue
        if remote_labels.get(k) != local_labels.get(k):
            log.warning(
                'Network {}: label "{}" has changed. It may need to be'
                " recreated.".format(local.true_name, k)
            )


# Traceback (AttributeError)
$ sudo -E docker-compose up --detach
[16436] Failed to execute script docker-compose
Traceback (most recent call last):
File "bin/docker-compose", line 6, in <module>
File "compose/cli/main.py", line 71, in main
File "compose/cli/main.py", line 127, in perform_command
File "compose/cli/main.py", line 1096, in up
File "compose/cli/main.py", line 1092, in up
File "compose/project.py", line 514, in up
File "compose/project.py", line 569, in initialize
File "compose/network.py", line 298, in initialize
File "compose/network.py", line 74, in ensure
File "compose/network.py", line 230, in check_remote_network_config
AttributeError: 'NoneType' object has no attribute 'keys'

# Fixed code
def check_remote_network_config(remote, local):
    if local.driver and remote.get("Driver") != local.driver:
        raise NetworkConfigChangedError(local.true_name, "driver")
    local_opts = local.driver_opts or {}
    remote_opts = remote.get("Options") or {}
    for k in set.union(set(remote_opts.keys()), set(local_opts.keys())):
        if k in OPTS_EXCEPTIONS:
            continue
        if remote_opts.get(k) != local_opts.get(k):
            raise NetworkConfigChangedError(local.true_name, 'option "{}"'.format(k))

    if local.ipam is not None:
        check_remote_ipam_config(remote, local)

    if local.internal is not None and local.internal != remote.get("Internal", False):
        raise NetworkConfigChangedError(local.true_name, "internal")
    if local.enable_ipv6 is not None and local.enable_ipv6 != remote.get(
        "EnableIPv6", False
    ):
        raise NetworkConfigChangedError(local.true_name, "enable_ipv6")

    local_labels = local.labels or {}
    remote_labels = remote.get("Labels") or {}
    for k in set.union(set(remote_labels.keys()), set(local_labels.keys())):
        if k.startswith(
            "com.docker."
        ):  # We are only interested in user-specified labels
            continue
        if remote_labels.get(k) != local_labels.get(k):
            log.warning(
                'Network {}: label "{}" has changed. It may need to be'
                " recreated.".format(local.true_name, k)
            )