FileResultStore.delete_expired crashes on JSON-materialized cache results

オープン 初心者向け
#1,813 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
75/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend, testing

調査の方向性

まず hamilton/caching/stores/file.py、特に FileResultStore.delete_expired() と _load_result_from_path() を確認し、次にファイルストアのテストでクリーンアップがカバーされているか調べます。対象を絞ったテストを実行し、JSONDataSaver と JSONDataLoader を使った回帰テストケースを追加します。クリーンアップが完了し、有効期限の切れていない結果を引き続き読み取れる状態になれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Current behavior

FileResultStore.delete_expired() raises UnpicklingError after storing a result with the built-in JSON saver/loader. The result can be read successfully before cleanup, and nothing has expired.

This prevents cleanup of a store containing valid JSON-materialized results.

Steps to reproduce

from pathlib import Path
from tempfile import TemporaryDirectory

from hamilton.caching.stores.file import FileResultStore
from hamilton.io.default_data_loaders import JSONDataLoader, JSONDataSaver

with TemporaryDirectory() as directory:
    store = FileResultStore(directory)
    store.set(
        "example",
        {"value": 1},
        saver_cls=JSONDataSaver,
        loader_cls=JSONDataLoader,
    )
    assert store.get("example") == {"value": 1}
    print(sorted(path.name for path in Path(directory).iterdir()), flush=True)
    store.delete_expired()
    assert store.get("example") == {"value": 1}

Observed output and traceback (paths shortened):

['example', 'example.json']
Traceback (most recent call last):
  File "repro.py", line 17, in <module>
    store.delete_expired()
  File "hamilton/caching/stores/file.py", line 138, in delete_expired
    stored_result = self._load_result_from_path(file_path)
  File "hamilton/caching/stores/file.py", line 55, in _load_result_from_path
    return StoredResult.load(data)
  File "hamilton/caching/stores/base.py", line 234, in load
    loaded = pickle.loads(raw)
_pickle.UnpicklingError: invalid load key, '{'.

Expected behavior

Cleanup should complete without attempting to unpickle the JSON payload, and the unexpired result should remain readable.

Library and system information

  • Hamilton 1.90.0, editable checkout at 2bd9dbc7ee22e1c2a4f6cd687a353aa0079d4d81
  • Python 3.11.17, macOS arm64
  • Compared both affected files (caching/stores/file.py and caching/stores/base.py) with upstream main at ef88b1e96140a01f3d72967316c2335f8b62a067; they are byte-for-byte identical.

Proposed contribution

set() writes a pickled loader reference and a separate .json payload into the same directory. delete_expired() iterates every directory entry and passes each to StoredResult.load(), including the JSON payload.

I would like to contribute a focused fix that distinguishes stored-result entries from materialized payloads, with a regression test showing cleanup preserves a readable JSON result. Would you be open to me taking this on, and is there a preferred way to identify those entries? I would keep any broader expiration/serialization redesign separate.

主要言語
Jupyter Notebook
スター
2.6k
フォーク
230
平均マージ
3日 3時間
マージ済み PR(30日)
22

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/hamilton のほかの issue

apache/hamilton の issue をすべて見る

似ている issue

Backend & API Design の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。