Quantum: Add Job.list_attachments() - #768
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Adds a new Job.list_attachments() API to enumerate blob names in a job’s output/input container, enabling callers to discover available attachments without downloading them.
Changes:
- Introduces
BaseJob.list_attachments()that resolves the effective container URI (job-linked or workspace-derived) and lists blob names. - Adds unit tests covering default container URI usage, workspace fallback, and explicit override behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| azure-quantum/azure/quantum/job/base_job.py | Adds list_attachments() to list blob names from the job container. |
| azure-quantum/tests/test_job_attachments.py | New tests validating container resolution logic and returned blob name list. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
5f7359c to
1b2582d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
azure-quantum/azure/quantum/job/base_job.py:366
download_attachment()returns the result ofreadall()(bytes), but the new return type annotation islist[str]. This makes the public API type contract incorrect for callers and static type checking.
def download_attachment(
self,
name: str,
container_uri: Optional[str] = None
) -> list[str]:
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
1b2582d to
64815d4
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
azure-quantum/azure/quantum/job/base_job.py:396
list_attachmentsis a public API but its return type is annotated as plainlist, which loses key/value information for callers. Since the method always returns a list of dicts with string keys, consider tightening the return annotation.
def list_attachments(
self,
container_uri: Optional[str] = None
) -> list:
azure-quantum/azure/quantum/job/base_job.py:366
download_attachmentnow advertises alist[str]return type, but it returns the result ofreadall()(bytes). This makes the public type contract incorrect and can break type checking / IDE hints.
This issue also appears on line 393 of the same file.
def download_attachment(
self,
name: str,
container_uri: Optional[str] = None
) -> list[str]:
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
64815d4 to
08dc1d3
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (3)
azure-quantum/azure/quantum/job/base_job.py:409
- The PR description says
Job.list_attachments(container_uri: Optional[str] = None)should resolve the container from an explicit argument (if provided) and return lightweight metadata dicts (name/size/lastModified). The current implementation has nocontainer_uriparameter and returns rawBlobPropertiesobjects, so the public API does not match the described contract. Consider aligning this method with the existingupload_attachment/download_attachmentcontainer resolution logic and returning metadata dicts.
def list_attachments(self) -> list[BlobProperties]:
""" Lists the attachments in the job's linked storage container. Attachments are blobs of
data created as part of the Job's execution, or they can be uploaded directly from Python
using the upload_attachment method.
azure-quantum/tests/test_job_attachments.py:39
- If
list_attachments()is intended (per PR description) to return lightweight metadata dicts, this test should validate the returned shape rather than returning the raw blob objects fromlist_blobs(). As written, the test would pass even if the method did no projection and returned SDK objects directly.
def test_list_attachments_returns_container_blobs(mock_container_client):
job = _job_with_container()
blob_a = Mock()
blob_b = Mock()
azure-quantum/tests/test_job_attachments.py:54
- The PR description states there are 3 tests, including coverage for an explicit
container_urioverride. This file currently has only 2 tests and does not verify that an explicitcontainer_uriis preferred overjob_details.container_uri/workspace.get_container_uri(...). Adding that test would prevent regressions in the container-resolution precedence.
@patch("azure.quantum.job.base_job.ContainerClient")
def test_list_attachments_uses_workspace_container_when_unset(mock_container_client):
workspace = Mock()
workspace.get_container_uri.return_value = CONTAINER_URI
job = _job_with_container(container_uri=None, workspace=workspace)
container = mock_container_client.from_container_url.return_value
container.list_blobs.return_value = []
result = job.list_attachments()
workspace.get_container_uri.assert_called_once_with(job_id="job-id")
mock_container_client.from_container_url.assert_called_once_with(CONTAINER_URI)
assert result == []
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Summary
Adds a new
Job.list_attachments()method to the Azure Quantum Python SDK that lists every blob in a job's Azure Storage output container, returning lightweight metadata (name, size, last modified) for each. This gives Python users a programmatic way to discover a job's associated files, without downloading them, complementing the existingupload_attachment/download_attachmentmethods.Changes
list_attachments() -> list[BlobProperties]. It resolves the job's linked storage container (fromself.details.container_uri, falling back toworkspace.get_container_uri(job_id=self.id)), opens aContainerClient, and returnslist(container_client.list_blobs()). ReturningBlobProperties` keeps the API consisten with other types listing APIs in the package rather than returning ad-hoc dicts.test_job_attachments.py(new)- unit testsTesting
testing_job_attachments.py- 2 tests, all passing:test_list_attachments_returns_container_blobs: returns the container's blob as-is.test_list_attachments_uses_workspace_container_when_unset: falls back toworkspace.get_container_uri(job_id= ...)when the job has no linked container URI.