Skip to content

Support relative blob paths in AzureBlobStorageIO#1478

Open
biefan wants to merge 1 commit intoAzure:mainfrom
biefan:fix-azure-blob-storage-relative-paths
Open

Support relative blob paths in AzureBlobStorageIO#1478
biefan wants to merge 1 commit intoAzure:mainfrom
biefan:fix-azure-blob-storage-relative-paths

Conversation

@biefan
Copy link
Contributor

@biefan biefan commented Mar 16, 2026

Summary

This updates AzureBlobStorageIO so that relative blob paths are handled consistently across blob operations.

Problem

Several AzureBlobStorageIO methods document or imply support for either:

  • a full blob URL, or
  • a relative blob path inside the configured container

In particular, read_file() explicitly documents relative-path support. However, the implementation always routed the input through parse_blob_url(), which only accepts full URLs and raises ValueError for relative paths.

That means calls such as:

await storage.read_file("dir1/dir2/sample.png")

fail immediately with ValueError("Invalid blob URL") even though the method contract says the relative path should be used as-is.

The same issue also affects path_exists() and is_file(), and it unnecessarily constrains write_file() to URL-only inputs as well.

Fix

  • add a small blob-name resolution helper that:
    • extracts the blob name from a full blob URL, or
    • passes relative blob paths through unchanged
  • use that helper in read_file(), write_file(), path_exists(), and is_file()

This keeps the existing full-URL behavior intact while making the relative-path behavior match the documented API.

Tests

Added regression coverage for relative-path handling in:

  • read_file()
  • path_exists()

Validation command:

.venv/bin/pytest tests/unit/models/test_storage_io.py -q

Validation result:

15 passed in 0.05s

Copy link
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

Updates AzureBlobStorageIO so callers can pass either a full Azure Blob URL or a relative blob path (within the configured container) consistently across blob operations.

Changes:

  • Added a _resolve_blob_name() helper to accept either full blob URLs or relative blob paths.
  • Updated read_file(), write_file(), path_exists(), and is_file() to use the helper instead of requiring URL parsing.
  • Added regression tests for relative-path handling in read_file() and path_exists().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
pyrit/models/storage_io.py Adds blob-name resolution helper and applies it across Azure blob operations to support relative paths.
tests/unit/models/test_storage_io.py Adds unit tests validating relative-path behavior for read_file() and path_exists().

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +268 to +272
parsed_url = urlparse(path_str)
if parsed_url.scheme and parsed_url.netloc:
_, blob_name = self.parse_blob_url(path_str)
return blob_name
return path_str
if not self._client_async:
await self._create_container_client_async()
_, blob_name = self.parse_blob_url(str(path))
blob_name = self._resolve_blob_name(path)
if not self._client_async:
await self._create_container_client_async()
_, blob_name = self.parse_blob_url(str(path))
blob_name = self._resolve_blob_name(path)
await self._create_container_client_async()
try:
_, blob_name = self.parse_blob_url(str(path))
blob_name = self._resolve_blob_name(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants