Skip to content

Fix audmodel.url() for Minio backends#54

Draft
hagenw wants to merge 1 commit into
mainfrom
url-for-minio
Draft

Fix audmodel.url() for Minio backends#54
hagenw wants to merge 1 commit into
mainfrom
url-for-minio

Conversation

@hagenw

@hagenw hagenw commented Jun 30, 2026

Copy link
Copy Markdown
Member

We have audmodel.url() which returns a link to the actual physical location of the model. It worked under filesystem and artifactory, but never under Minio for which it just returned the relative path on the server. But you can also create absolute path for Minio/S3 as well.

This pull request introduces changes the behavior of audmodel.url() to return absolute paths. It uses internal hidden methods from audbackend, but we need to do the same for filesystem as long as we do not want to extend audbackend.

This is a breaking change, but I would call it a fix.

@sourcery-ai

sourcery-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This pull request refactors audmodel.url() to construct absolute URLs for both filesystem and Minio/S3 backends by introducing a shared helper and expanding tests to validate URL behavior, including a new Minio-specific test.

Sequence diagram for updated audmodel.url() URL construction

sequenceDiagram
    actor Client
    participant audmodel_api as audmodel_api
    participant backend_interface as backend_interface
    participant backend as backend

    Client->>audmodel_api: url(uid, type, version, backend_interface)
    audmodel_api->>backend_interface: _path_with_version(path, version)
    backend_interface-->>audmodel_api: backend_path
    audmodel_api->>audmodel_api: _url(backend_interface, backend_path)
    audmodel_api->>backend_interface: sep.join(parts)
    audmodel_api->>backend_interface: backend

    alt [FileSystem backend]
        audmodel_api->>backend: _root
        audmodel_api->>backend_interface: sep.join([backend._root, backend_path])
    else [Minio backend]
        audmodel_api->>backend: host
        audmodel_api->>backend: repository
        audmodel_api->>backend: path(backend_path)
        audmodel_api->>backend_interface: sep.join([scheme_host, backend.repository, backend.path(backend_path)])
    end

    audmodel_api-->>Client: absolute_url
Loading

File-Level Changes

Change Details Files
Introduce a shared helper to convert backend paths into absolute URLs for filesystem and Minio/S3 backends and use it from audmodel.url().
  • Add internal _url() helper in audmodel.core.api to map backend paths to absolute URLs
  • Implement filesystem handling by prefixing backend paths with the backend root using the backend interface separator
  • Implement Minio handling by building an http/https URL from the Minio client base URL, host, repository, and object path
  • Refactor url() to delegate URL construction to _url() after computing the versioned backend path
audmodel/core/api.py
Expand and adjust tests for audmodel.url() to cover error cases, filesystem absolute paths, and Minio/S3 URL construction.
  • Extend test_url() to first compute a model UID and verify that invalid type arguments raise ValueError
  • Add assertions that filesystem URLs returned by audmodel.url() exist on disk, start with the expected repository root, and have correct filenames/extensions for model, header, and meta
  • Add a dedicated test_url_minio() that constructs a Minio backend interface, builds a versioned header path, and verifies that audmodel.core.api._url() returns the expected https URL for S3
  • Import audmodel.core.api and audmodel.core.define to support testing of the internal helper and UID-based paths
tests/test_api.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (407d4e9) to head (1c3884f).

Additional details and impacted files
Files with missing lines Coverage Δ
audmodel/core/api.py 100.0% <100.0%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 1 issue, and left some high level feedback:

  • The new _url() helper relies heavily on private attributes and methods of the backend (e.g., _root, _client._base_url, path), which may be brittle; consider encapsulating this logic in audbackend or exposing public helpers instead of reaching into internals.
  • _url() silently returns the unmodified path for backend types other than FileSystem and Minio; if additional backends are expected, consider making the behavior explicit (e.g., raising, or adding a clear default handling) to avoid ambiguous results.
  • The Minio URL construction assumes a specific host format and scheme derivation; it might be safer to reuse existing URL-building utilities or centralize this logic so changes to Minio configuration or client behavior don’t require touching audmodel.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `_url()` helper relies heavily on private attributes and methods of the backend (e.g., `_root`, `_client._base_url`, `path`), which may be brittle; consider encapsulating this logic in audbackend or exposing public helpers instead of reaching into internals.
- `_url()` silently returns the unmodified path for backend types other than FileSystem and Minio; if additional backends are expected, consider making the behavior explicit (e.g., raising, or adding a clear default handling) to avoid ambiguous results.
- The Minio URL construction assumes a specific host format and scheme derivation; it might be safer to reuse existing URL-building utilities or centralize this logic so changes to Minio configuration or client behavior don’t require touching audmodel.

## Individual Comments

### Comment 1
<location path="audmodel/core/api.py" line_range="1071-1080" />
<code_context>
+def _url(
</code_context>
<issue_to_address>
**issue (bug_risk):** Behavior for unsupported backend types may not match the function’s URL-centric contract.

The docstring says `_url` converts a backend path into a URL, but for backends other than `FileSystem` and `Minio` it returns the raw `path`. This can mask misconfigurations or new backend types that aren’t wired up correctly. Consider failing explicitly (e.g., raising for unsupported backends), returning `None`, or updating the docs to state that non-URL-capable backends return the backend-relative path unchanged.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread audmodel/core/api.py
Comment on lines +1071 to +1080
def _url(
backend_interface: audbackend.interface.Base,
path: str,
) -> str:
r"""Convert a backend path into a URL.

Depending on the underlying backend
of the given backend interface,
the path on the backend
is turned into a URL

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.

issue (bug_risk): Behavior for unsupported backend types may not match the function’s URL-centric contract.

The docstring says _url converts a backend path into a URL, but for backends other than FileSystem and Minio it returns the raw path. This can mask misconfigurations or new backend types that aren’t wired up correctly. Consider failing explicitly (e.g., raising for unsupported backends), returning None, or updating the docs to state that non-URL-capable backends return the backend-relative path unchanged.

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.

1 participant