Found during the docs audit (#367).
StateManager._decode_state (fastapi_cachex/state/manager.py, return StateData(**state_dict)) catches ValueError only. When the stored state is valid JSON but not an object (for example [1, 2] or "x"), StateData(**state_dict) raises TypeError: argument after ** must be a mapping, which escapes:
| Method |
Documented |
Actual |
validate_state(state) |
False for malformed data |
TypeError |
get_state_metadata(state) |
None for malformed data |
TypeError |
consume_state(state) |
StateDataError |
TypeError |
Repro: create a state on a MemoryBackend, overwrite its entry with CacheEntry(fingerprint, b"[1, 2]", media_type), then call the three methods.
Proposal
Check isinstance(state_dict, dict) after json.loads (or also catch TypeError) and raise StateDataError. Add a test for each method with a non-object JSON value.
Found during the docs audit (#367).
StateManager._decode_state(fastapi_cachex/state/manager.py,return StateData(**state_dict)) catchesValueErroronly. When the stored state is valid JSON but not an object (for example[1, 2]or"x"),StateData(**state_dict)raisesTypeError: argument after ** must be a mapping, which escapes:validate_state(state)Falsefor malformed dataTypeErrorget_state_metadata(state)Nonefor malformed dataTypeErrorconsume_state(state)StateDataErrorTypeErrorRepro: create a state on a
MemoryBackend, overwrite its entry withCacheEntry(fingerprint, b"[1, 2]", media_type), then call the three methods.Proposal
Check
isinstance(state_dict, dict)afterjson.loads(or also catchTypeError) and raiseStateDataError. Add a test for each method with a non-object JSON value.