# Buggy code
def list_policy_assignment(
    cmd, disable_scope_strict_match=None, resource_group_name=None, scope=None
):
    policy_client = _resource_policy_client_factory(cmd.cli_ctx)
    if scope and not is_valid_resource_id(scope):
        parts = scope.strip("/").split("/")
        if len(parts) == 4:
            resource_group_name = parts[3]
        elif len(parts) == 2:
            # rarely used, but still verify
            if parts[1].lower() != policy_client.config.subscription_id.lower():
                raise CLIError("Please use current active subscription's id")
        else:
            err = (
                "Invalid scope '{}', it should point to a resource group or a resource"
            )
            raise CLIError(err.format(scope))
        scope = None

    _scope = _build_policy_scope(
        policy_client.config.subscription_id, resource_group_name, scope
    )
    if resource_group_name:
        result = policy_client.policy_assignments.list_for_resource_group(
            resource_group_name
        )
    elif scope:
        # pylint: disable=redefined-builtin
        id = parse_resource_id(scope)
        parent_resource_path = (
            "" if not id.get("child_name_1") else (id["type"] + "/" + id["name"])
        )
        resource_type = id.get("child_type_1") or id["type"]
        resource_name = id.get("child_name_1") or id["name"]
        result = policy_client.policy_assignments.list_for_resource(
            id["resource_group"],
            id["namespace"],
            parent_resource_path,
            resource_type,
            resource_name,
        )
    else:
        result = policy_client.policy_assignments.list()

    if not disable_scope_strict_match:
        result = [i for i in result if _scope.lower() == i.scope.lower()]

    return result


# Traceback (KeyError)
'type'
Traceback (most recent call last):
Temp\pip-install-dsvrkf2x\knack\knack\cli.py, ln 206, in invoke
azure\cli\core\commands\__init__.py, ln 560, in execute
azure\cli\core\commands\__init__.py, ln 618, in _run_jobs_serially
azure\cli\core\commands\__init__.py, ln 611, in _run_job
Local\Temp\pip-install-dsvrkf2x\six\six.py, ln 693, in reraise
azure\cli\core\commands\__init__.py, ln 588, in _run_job
azure\cli\core\commands\__init__.py, ln 297, in __call__
azure-cli-core\azure\cli\core\__init__.py, ln 461, in default_command_handler
azure\cli\command_modules\resource\custom.py, ln 1141, in list_policy_assignment
KeyError: 'type'

# Fixed code
def list_policy_assignment(
    cmd, disable_scope_strict_match=None, resource_group_name=None, scope=None
):
    from azure.cli.core.commands.client_factory import get_subscription_id

    policy_client = _resource_policy_client_factory(cmd.cli_ctx)
    _scope = _build_policy_scope(
        get_subscription_id(cmd.cli_ctx), resource_group_name, scope
    )
    id_parts = parse_resource_id(_scope)
    subscription = id_parts.get("subscription")
    resource_group = id_parts.get("resource_group")
    resource_type = id_parts.get("child_type_1") or id_parts.get("type")
    resource_name = id_parts.get("child_name_1") or id_parts.get("name")

    if all([resource_type, resource_group, subscription]):
        namespace = id_parts.get("namespace")
        parent_resource_path = (
            ""
            if not id_parts.get("child_name_1")
            else (id_parts["type"] + "/" + id_parts["name"])
        )
        result = policy_client.policy_assignments.list_for_resource(
            resource_group,
            namespace,
            parent_resource_path,
            resource_type,
            resource_name,
        )
    elif resource_group:
        result = policy_client.policy_assignments.list_for_resource_group(
            resource_group
        )
    elif subscription:
        result = policy_client.policy_assignments.list()
    elif scope:
        raise CLIError("usage error `--scope`: must be a fully qualified ARM ID.")
    else:
        raise CLIError(
            "usage error: --scope ARM_ID | --resource-group NAME | --subscription ID"
        )

    if not disable_scope_strict_match:
        result = [i for i in result if _scope.lower() == i.scope.lower()]

    return result