FileResultStore.delete_expired crashes on JSON-materialized cache results

Aperta Adatta ai principianti
#1,813 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend, testing

Direzione di ricerca

Inizia da hamilton/caching/stores/file.py, in particolare da FileResultStore.delete_expired() e _load_result_from_path(), poi esamina i test dell’archivio di file per verificare la copertura della pulizia. Esegui i test mirati e aggiungi un caso di regressione usando JSONDataSaver e JSONDataLoader; il lavoro è concluso quando la pulizia termina e il risultato non scaduto rimane leggibile.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Jupyter Notebook
Stelle
2.6k
Fork
230
Merge medio
3g 3h
PR unite (30g)
22

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/hamilton

Tutte le issue di apache/hamilton

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.