FileResultStore.delete_expired crashes on JSON-materialized cache results

Đang mở Phù hợp với người mới
#1,813 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend, testing

Hướng nghiên cứu

Bắt đầu với hamilton/caching/stores/file.py, đặc biệt là FileResultStore.delete_expired() và _load_result_from_path(), sau đó kiểm tra các bài kiểm thử của kho lưu trữ tệp để xem mức độ bao phủ của việc dọn dẹp. Chạy các bài kiểm thử tập trung và thêm một trường hợp hồi quy sử dụng JSONDataSaver và JSONDataLoader; hoàn thành khi việc dọn dẹp kết thúc và kết quả chưa hết hạn vẫn đọc được.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Jupyter Notebook
Star
2.6k
Fork
230
Merge trung bình
3 ngày 3 giờ
Pull request đã merge (30 ngày)
22

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/hamilton

Tất cả issue của apache/hamilton

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.