Skip to content

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

Open
johanyim wants to merge 1 commit into
Azure: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 into
Azure:devfrom
johanyim:patch-1

Conversation

@johanyim

@johanyim johanyim commented Apr 23, 2026

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

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


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

azure-client-tools-bot-prd Bot commented Apr 23, 2026

Copy link
Copy Markdown
❌AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.13
️✔️acs
️✔️latest
️✔️3.12
️✔️3.13
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.13
️✔️ams
️✔️latest
️✔️3.12
️✔️3.13
️✔️apim
️✔️latest
️✔️3.12
️✔️3.13
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.13
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️aro
️✔️latest
️✔️3.12
️✔️3.13
️✔️backup
️✔️latest
️✔️3.12
️✔️3.13
❌batch
❌latest
❌3.12
Type Test Case Error Message Line
Failed test_batch_validate_file_destination self = <azure.cli.command_modules.batch.tests.latest.test_batch_commands.TestBatchValidators testMethod=test_batch_validate_file_destination>

    def test_batch_validate_file_destination(self):
        ns = TestObj()
        validators.validate_file_destination(ns)
        self.assertFalse(hasattr(ns, 'destination'))
    
        ns.destination = os.path.dirname(file)
        ns.file_name = "/wd/stdout.txt"
>       validators.validate_file_destination(ns)

src/azure-cli/azure/cli/command_modules/batch/tests/latest/test_batch_commands.py:147: 
 
                                       

namespace = <azure.cli.command_modules.batch.tests.latest.test_batch_commands.TestObj object at 0x7f982218ccb0>

    def validate_file_destination(namespace):
        """Validate the destination path for a file download."""
        try:
            path = namespace.destination
        except AttributeError:
            return
        # TODO: Need to confirm this logic...
        file_path = path
        file_dir = os.path.dirname(path)
        if os.path.isdir(path):
>           file_name = os.path.basename(namespace.file_path)
                                         ^^^^^^^^^^^^^^^^^^^
E           AttributeError: 'TestObj' object has no attribute 'file_path'. Did you mean: 'file_name'?

src/azure-cli/azure/cli/command_modules/batch/_validators.py:242: AttributeError
azure/cli/command_modules/batch/tests/latest/test_batch_commands.py:139
❌3.13
Type Test Case Error Message Line
Failed test_batch_validate_file_destination self = <azure.cli.command_modules.batch.tests.latest.test_batch_commands.TestBatchValidators testMethod=test_batch_validate_file_destination>

    def test_batch_validate_file_destination(self):
        ns = TestObj()
        validators.validate_file_destination(ns)
        self.assertFalse(hasattr(ns, 'destination'))
    
        ns.destination = os.path.dirname(file)
        ns.file_name = "/wd/stdout.txt"
>       validators.validate_file_destination(ns)

src/azure-cli/azure/cli/command_modules/batch/tests/latest/test_batch_commands.py:147: 
 
                                       

namespace = <azure.cli.command_modules.batch.tests.latest.test_batch_commands.TestObj object at 0x7f74f8117750>

    def validate_file_destination(namespace):
        """Validate the destination path for a file download."""
        try:
            path = namespace.destination
        except AttributeError:
            return
        # TODO: Need to confirm this logic...
        file_path = path
        file_dir = os.path.dirname(path)
        if os.path.isdir(path):
>           file_name = os.path.basename(namespace.file_path)
                                         ^^^^^^^^^^^^^^^^^^^
E           AttributeError: 'TestObj' object has no attribute 'file_path'. Did you mean: 'file_name'?

src/azure-cli/azure/cli/command_modules/batch/_validators.py:242: AttributeError
azure/cli/command_modules/batch/tests/latest/test_batch_commands.py:139
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.13
️✔️billing
️✔️latest
️✔️3.12
️✔️3.13
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.13
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.13
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.13
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.13
️✔️config
️✔️latest
️✔️3.12
️✔️3.13
️✔️configure
️✔️latest
️✔️3.12
️✔️3.13
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.13
️✔️container
️✔️latest
️✔️3.12
️✔️3.13
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.13
️✔️core
️✔️latest
️✔️3.12
️✔️3.13
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.13
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.13
️✔️dls
️✔️latest
️✔️3.12
️✔️3.13
️✔️dms
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.13
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.13
️✔️find
️✔️latest
️✔️3.12
️✔️3.13
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.13
️✔️identity
️✔️latest
️✔️3.12
️✔️3.13
️✔️iot
️✔️latest
️✔️3.12
️✔️3.13
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.13
️✔️lab
️✔️latest
️✔️3.12
️✔️3.13
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️maps
️✔️latest
️✔️3.12
️✔️3.13
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.13
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.13
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.13
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.13
️✔️network
️✔️latest
️✔️3.12
️✔️3.13
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.13
️✔️postgresql
️✔️latest
️✔️3.12
️✔️3.13
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.13
️✔️profile
️✔️latest
️✔️3.12
️✔️3.13
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.13
️✔️redis
️✔️latest
️✔️3.12
️✔️3.13
️✔️relay
️✔️latest
️✔️3.12
️✔️3.13
️✔️resource
️✔️latest
️✔️3.12
️✔️3.13
️✔️role
️✔️latest
️✔️3.12
️✔️3.13
️✔️search
️✔️latest
️✔️3.12
️✔️3.13
️✔️security
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.13
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.13
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.13
️✔️sql
️✔️latest
️✔️3.12
️✔️3.13
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.13
️✔️storage
️✔️latest
️✔️3.12
️✔️3.13
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.13
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.13
️✔️util
️✔️latest
️✔️3.12
️✔️3.13
️✔️vm
️✔️latest
️✔️3.12
️✔️3.13

@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

azure-client-tools-bot-prd Bot commented Apr 23, 2026

Copy link
Copy Markdown
️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@yonzhan

yonzhan commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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)

Copilot AI Apr 23, 2026

Copy link

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
@yanzhudd

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@yanzhudd yanzhudd changed the title [Batch] az batch task file download Fixed AttributeError when downloading batch task files [Batch] az batch task file download: Fixed AttributeError when downloading batch task files May 25, 2026
@yanzhudd

Copy link
Copy Markdown
Contributor

Is this PR ready to review/merge?
Please note that the code completion time for the upcoming release is on 05/26/2026 at 06:00 UTC. If you want to catch up the release train, please let us know asap.

@yanzhudd

Copy link
Copy Markdown
Contributor

Please note that the code completion time for the upcoming release train is on 06/30/2026 at 02:00 UTC. If you want it to be released in this sprint, please get it ready asap and ping me in Teams directly.

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