Skip to content

Avoid duplicate file read in FetcherBase.get_raw failure path #2149

@Jay2006sawant

Description

@Jay2006sawant

Describe the bug

FetcherBase.get_raw() in trestle/core/remote/cache.py performs a duplicate file read on failure.

When file_utils.load_file(self._cached_object_path) raises, the code immediately retries the exact same call in the except block without changing path, state, or parser. This causes redundant work and duplicate failure path execution.

To Reproduce

Steps to reproduce the behavior:

  1. Create a LocalFetcher with any readable cache file path.
  2. Monkeypatch trestle.common.file_utils.load_file to always raise an exception.
  3. Call fetcher.get_raw().
  4. Count/inspect calls to load_file.
  5. See that load_file is called twice for a single get_raw() invocation before raising TrestleError.

Expected behavior

If load_file fails once, get_raw() should raise a single wrapped TrestleError without retrying the exact same read operation.

Screenshots / Logs.

Runtime verification output from local check (call counter):

2

This confirms duplicate invocation of load_file in the failure path.

Environment

  • OS: Linux 6.8.0-101-generic
  • Python version: 3.10.12
  • Installed packages: local editable install via pip install -e ".[dev]", project setup with make develop

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions