Skip to content

[Batch] az batch task file download Fixed AttributeError when downloading batch task files#33253

Open
johanyim wants to merge 1 commit intoAzure:devfrom
johanyim:patch-1
Open

[Batch] az batch task file download Fixed AttributeError when downloading batch task files#33253
johanyim wants to merge 1 commit intoAzure:devfrom
johanyim:patch-1

Conversation

@johanyim
Copy link
Copy Markdown

Related command
az batch task file download

Description

This PR fixes a bug when downloading a file from the working directory (wd/) of a batch task. The command

az batch task file download \
    --job-id "job-1" \
    --task-id "task-1" \
    --file-path "wd/path/to/file.txt" \
    --destination "local/machine/output/"

will throw an error such as:

AttributeError: 'Namespace' object has no attribute 'file_name'. Did you mean: 'file_path'?

cli.azure.cli.core.azclierror: 'Namespace' object has no attribute 'file_name'
az_command_data_logger: 'Namespace' object has no attribute 'file_name'

This PR fixes that incorrect attribute name such that the command will work as intended.

Testing Guide
Consider a batch job (job-1) with a task (task-1). Create a directory on the local machine in your working directory, (./output/) and run the following to extract the stdout.txt file from the task, assuming it exists.

az batch task file download \
    --job-id "job-1" \
    --task-id "task-1" \
    --file-path "wd/stdout.txt" \
    --destination "./output/"

History Notes

[az batch file task download]: FIX: validate_file_destination incorrect attribute name


This checklist is used to make sure that common guidelines for a pull request are followed.

Copilot AI review requested due to automatic review settings April 23, 2026 13:51
@azure-client-tools-bot-prd
Copy link
Copy Markdown

Validation for Azure CLI Full Test Starting...

Thanks for your contribution!

@azure-client-tools-bot-prd
Copy link
Copy Markdown

Hi @johanyim,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@azure-client-tools-bot-prd
Copy link
Copy Markdown

Validation for Breaking Change Starting...

Thanks for your contribution!

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Apr 23, 2026

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link
Copy Markdown

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

@microsoft-github-policy-service microsoft-github-policy-service Bot added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label Apr 23, 2026
@microsoft-github-policy-service
Copy link
Copy Markdown
Contributor

Thank you for your contribution @johanyim! We will review the pull request and get back to you soon.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes az batch task file download failing with an AttributeError when the destination is a directory by using the correct namespace attribute for deriving the output filename.

Changes:

  • Update validate_file_destination to use namespace.file_path (instead of namespace.file_name) when computing the downloaded filename.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

file_dir = os.path.dirname(path)
if os.path.isdir(path):
file_name = os.path.basename(namespace.file_name)
file_name = os.path.basename(namespace.file_path)
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This validator now reads namespace.file_path, but the existing unit test test_batch_validate_file_destination still sets ns.file_name (see batch/tests/latest/test_batch_commands.py). CI will likely fail unless the test (and any other callers constructing a namespace for this validator) is updated to use file_path instead of file_name.

Suggested change
file_name = os.path.basename(namespace.file_path)
source_path = getattr(namespace, 'file_path', None) or getattr(namespace, 'file_name', None)
if not source_path:
raise ValueError("Missing file path for destination filename resolution.")
file_name = os.path.basename(source_path)

Copilot uses AI. Check for mistakes.
@yonzhan yonzhan assigned yanzhudd and zhoxing-ms and unassigned zhoxing-ms and yanzhudd Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

act-observability-squad Auto-Assign Auto assign by bot Batch az batch customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants