Skip to content

fix: async cache_clear() TypeError + nested numpy serialization#54

Merged
27Bslash6 merged 2 commits intomainfrom
fix/49-50-async-cache-clear-and-nested-numpy
Feb 22, 2026
Merged

fix: async cache_clear() TypeError + nested numpy serialization#54
27Bslash6 merged 2 commits intomainfrom
fix/49-50-async-cache-clear-and-nested-numpy

Conversation

@27Bslash6
Copy link
Contributor

Summary

Combined fix for two related serialization/decorator bugs.

Fix 1: cache_clear() broken for async functions (#49)

cache_clear() called ainvalidate_cache() without awaiting, silently discarding the coroutine — cache was never cleared. Now raises TypeError directing users to await fn.ainvalidate_cache().

Root cause: wrapper.py:1395 — sync function cannot await a coroutine.

Fix 2: serializer="auto" fails on nested numpy arrays (#50)

_auto_default() had no handler for ndarray, so msgpack.packb() raised TypeError when numpy arrays were nested inside dicts or lists (despite documentation claiming support). Added __ndarray__ marker to _auto_default() and _auto_object_hook() for roundtrip serialization.

Root cause: Top-level numpy detection only; msgpack fallback path had no numpy handler.

Test plan

Issue #49 (4 tests)

  • test_cache_clear_raises_type_error_for_async_function
  • test_cache_clear_error_message_suggests_ainvalidate
  • test_cache_clear_does_not_raise_for_sync_function (regression guard)
  • test_async_ainvalidate_cache_still_works

Issue #50 (19 tests)

  • Dict with 1D/2D/float64/multiple numpy arrays
  • Lists containing numpy arrays
  • Deeply nested structures, mixed types (numpy + datetime + UUID + set)
  • Edge cases: empty array, 0-d scalar, 3D tensor
  • With and without ByteStorage integrity checking
  • Corruption detection: malformed __ndarray__ markers

Closes #49
Closes #50

cache_clear() called ainvalidate_cache() without awaiting, silently
discarding the coroutine. The cache was never actually cleared.

Now raises TypeError directing users to await fn.ainvalidate_cache().

Closes #49
_auto_default() had no handler for ndarray, so msgpack.packb() raised
TypeError when traversing container types with nested numpy arrays.

Added __ndarray__ marker to _auto_default/_auto_object_hook for
roundtrip serialization of nested arrays via the msgpack fallback path.

Closes #50
@codecov
Copy link

codecov bot commented Feb 22, 2026

Codecov Report

❌ Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/cachekit/serializers/auto_serializer.py 0.00% 7 Missing and 1 partial ⚠️
src/cachekit/decorators/wrapper.py 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@27Bslash6 27Bslash6 merged commit 5a9c8ca into main Feb 22, 2026
36 of 37 checks passed
@27Bslash6 27Bslash6 deleted the fix/49-50-async-cache-clear-and-nested-numpy branch February 22, 2026 02:57
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.

serializer="auto" fails on numpy arrays nested in dicts cache_clear() broken for async-decorated functions

1 participant