# Buggy code
def acr_pack_build(
    cmd,  # pylint: disable=too-many-locals
    client,
    registry_name,
    image_name,
    source_location,
    builder=ORYX_PACK_BUILDER_IMAGE,
    pull=False,
    no_format=False,
    no_logs=False,
    no_wait=False,
    timeout=None,
    resource_group_name=None,
    platform=None,
    auth_mode=None,
):
    registry, resource_group_name = get_registry_by_name(cmd.cli_ctx, registry_name)

    client_registries = cf_acr_registries(cmd.cli_ctx)
    source_location = prepare_source_location(
        source_location, client_registries, registry_name, resource_group_name
    )
    if not source_location:
        raise CLIError("Building with Buildpacks requires a valid source location.")

    platform_os, platform_arch, platform_variant = get_validate_platform(cmd, platform)
    OS = cmd.get_models("OS")
    if platform_os != OS.linux.value.lower():
        raise CLIError("Building with Buildpacks is only supported on Linux.")

    if builder != ORYX_PACK_BUILDER_IMAGE and not pull:
        logger.warning(
            "Using a non-default builder image; `--pull` is probably needed as well"
        )

    registry_prefixes = "{{.Run.Registry}}/", registry.login_server + "/"
    # If the image name doesn't have any required prefix, add it
    if all((not image_name.startswith(prefix) for prefix in registry_prefixes)):
        original_image_name = image_name
        image_name = registry_prefixes[0] + image_name
        logger.debug(
            "Modified image name from %s to %s", original_image_name, image_name
        )

    yaml_body = PACK_TASK_YAML_FMT.format(
        image_name=image_name, builder=builder, no_pull="--no-pull" if not pull else ""
    )

    EncodedTaskRunRequest, PlatformProperties = cmd.get_models(
        "EncodedTaskRunRequest", "PlatformProperties"
    )

    request = EncodedTaskRunRequest(
        encoded_task_content=base64.b64encode(yaml_body.encode()).decode(),
        source_location=source_location,
        timeout=timeout,
        platform=PlatformProperties(
            os=platform_os, architecture=platform_arch, variant=platform_variant
        ),
        credentials=get_custom_registry_credentials(cmd=cmd, auth_mode=auth_mode),
    )

    queued = LongRunningOperation(cmd.cli_ctx)(
        client_registries.schedule_run(
            resource_group_name=resource_group_name,
            registry_name=registry_name,
            run_request=request,
        )
    )

    run_id = queued.run_id
    logger.warning("Queued a run with ID: %s", run_id)

    if no_wait:
        return queued

    logger.warning("Waiting for an agent...")

    if no_logs:
        from ._run_polling import get_run_with_polling

        return get_run_with_polling(
            cmd, client, run_id, registry_name, resource_group_name
        )

    return stream_logs(
        client, run_id, registry_name, resource_group_name, no_format, True
    )


# Traceback (AttributeError)
This command group is in preview. It may be changed/removed in a future release.
Sending context to registry: <myregistry>...
The command failed with an unexpected error. Here is the traceback:

'RegistriesOperations' object has no attribute 'schedule_run'
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/knack/cli.py", line 206, in invoke
cmd_result = self.invocation.execute(args)
File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 578, in execute
raise ex
File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 636, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 629, in _run_job
six.reraise(*sys.exc_info())
File "/usr/local/lib/python3.6/site-packages/six.py", line 693, in reraise
raise value
File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 606, in _run_job
result = cmd_copy(params)
File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 305, in __call__
return self.handler(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 485, in default_command_handler
return op(**command_args)
File "/usr/local/lib/python3.6/site-packages/azure/cli/command_modules/acr/pack.py", line 89, in acr_pack_build
queued = LongRunningOperation(cmd.cli_ctx)(client_registries.schedule_run(
AttributeError: 'RegistriesOperations' object has no attribute 'schedule_run'

# Fixed code
def acr_pack_build(
    cmd,  # pylint: disable=too-many-locals
    client,
    registry_name,
    image_name,
    source_location,
    builder=ORYX_PACK_BUILDER_IMAGE,
    pull=False,
    no_format=False,
    no_logs=False,
    no_wait=False,
    timeout=None,
    resource_group_name=None,
    platform=None,
    auth_mode=None,
):
    registry, resource_group_name = get_registry_by_name(cmd.cli_ctx, registry_name)

    client_registries = cf_acr_registries_tasks(cmd.cli_ctx)
    source_location = prepare_source_location(
        source_location, client_registries, registry_name, resource_group_name
    )
    if not source_location:
        raise CLIError("Building with Buildpacks requires a valid source location.")

    platform_os, platform_arch, platform_variant = get_validate_platform(cmd, platform)
    OS = cmd.get_models("OS")
    if platform_os != OS.linux.value.lower():
        raise CLIError("Building with Buildpacks is only supported on Linux.")

    if builder != ORYX_PACK_BUILDER_IMAGE and not pull:
        logger.warning(
            "Using a non-default builder image; `--pull` is probably needed as well"
        )

    registry_prefixes = "{{.Run.Registry}}/", registry.login_server + "/"
    # If the image name doesn't have any required prefix, add it
    if all((not image_name.startswith(prefix) for prefix in registry_prefixes)):
        original_image_name = image_name
        image_name = registry_prefixes[0] + image_name
        logger.debug(
            "Modified image name from %s to %s", original_image_name, image_name
        )

    yaml_body = PACK_TASK_YAML_FMT.format(
        image_name=image_name, builder=builder, no_pull="--no-pull" if not pull else ""
    )

    EncodedTaskRunRequest, PlatformProperties = cmd.get_models(
        "EncodedTaskRunRequest", "PlatformProperties"
    )

    request = EncodedTaskRunRequest(
        encoded_task_content=base64.b64encode(yaml_body.encode()).decode(),
        source_location=source_location,
        timeout=timeout,
        platform=PlatformProperties(
            os=platform_os, architecture=platform_arch, variant=platform_variant
        ),
        credentials=get_custom_registry_credentials(cmd=cmd, auth_mode=auth_mode),
    )

    queued = LongRunningOperation(cmd.cli_ctx)(
        client_registries.schedule_run(
            resource_group_name=resource_group_name,
            registry_name=registry_name,
            run_request=request,
        )
    )

    run_id = queued.run_id
    logger.warning("Queued a run with ID: %s", run_id)

    if no_wait:
        return queued

    logger.warning("Waiting for an agent...")

    if no_logs:
        from ._run_polling import get_run_with_polling

        return get_run_with_polling(
            cmd, client, run_id, registry_name, resource_group_name
        )

    return stream_logs(
        client, run_id, registry_name, resource_group_name, no_format, True
    )