Skip to content

Commit ac9313a

Browse files
committed
fix: only trigger L1-only mode for explicit backend=None at decorator level
Remove buggy check that treated DecoratorConfig.backend defaulting to None as L1-only mode. Now only @cache(backend=None) triggers L1-only. For L1-only with presets, use: @cache(backend=None, config=...)
1 parent 37e6e0c commit ac9313a

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/cachekit/decorators/intent.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@ def decorator(f: F) -> F:
135135
if backend is not None:
136136
override_dict["backend"] = backend
137137
resolved_config = replace(config, **override_dict)
138-
# Check if config explicitly specifies backend=None (L1-only mode via config)
139-
if not _explicit_l1_only and resolved_config.backend is None:
140-
_explicit_l1_only = True
141138
# Intent-based presets (renamed per Task 6)
142139
elif _intent == "minimal": # Renamed from "fast"
143140
resolved_config = DecoratorConfig.minimal(backend=backend, **manual_overrides)
@@ -160,12 +157,10 @@ def decorator(f: F) -> F:
160157
# No intent specified - use default DecoratorConfig with overrides
161158
resolved_config = DecoratorConfig(backend=backend, **manual_overrides)
162159

163-
# Check if resolved config has backend=None (L1-only mode)
164-
# This catches both explicit backend=None in manual_overrides AND backend=None via config presets
165-
if not _explicit_l1_only and resolved_config.backend is None:
166-
_explicit_l1_only = True
167-
168160
# Delegate to wrapper factory with L1-only mode flag
161+
# Note: _explicit_l1_only is ONLY set when backend=None was explicitly passed
162+
# via manual_overrides. DecoratorConfig.backend defaults to None, but that
163+
# should NOT trigger L1-only mode - it should fall back to the provider.
169164
return _apply_cache_logic(f, resolved_config, _l1_only_mode=_explicit_l1_only) # type: ignore[return-value]
170165

171166
# Handle both @cache and @cache() syntax

tests/unit/test_l1_only_mode.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,14 @@ def slow_function() -> int:
109109

110110
def test_config_minimal_with_backend_none(self):
111111
"""
112-
DecoratorConfig.minimal(backend=None) should also use L1-only mode.
112+
Test L1-only mode with DecoratorConfig preset AND backend=None.
113113
114-
The bug can also occur via config objects that specify backend=None.
114+
NOTE: L1-only mode requires backend=None at the decorator level, not in config.
115+
This is because DecoratorConfig.backend defaults to None, and we can't
116+
distinguish "explicit None" from "default None" in the config.
117+
118+
Correct usage for L1-only with presets:
119+
@cache(backend=None, config=DecoratorConfig.minimal())
115120
"""
116121
from cachekit.config import DecoratorConfig
117122
from cachekit.decorators import cache
@@ -121,7 +126,8 @@ def test_config_minimal_with_backend_none(self):
121126

122127
call_count = 0
123128

124-
@cache(config=DecoratorConfig.minimal(backend=None))
129+
# L1-only mode: backend=None passed directly to @cache, config for preset settings
130+
@cache(backend=None, config=DecoratorConfig.minimal())
125131
def minimal_func() -> str:
126132
nonlocal call_count
127133
call_count += 1

0 commit comments

Comments
 (0)