aiocache icon indicating copy to clipboard operation
aiocache copied to clipboard

JsonSerializer & SimpleMemoryBackend: get after increment raises TypeError

Open Sergei-Rudenkov opened this issue 4 years ago • 2 comments

As result: TypeError the JSON object must be str, bytes or bytearray, not int

Sergei-Rudenkov avatar Apr 10 '20 21:04 Sergei-Rudenkov

pull request with fix: https://github.com/argaen/aiocache/pull/483

Sergei-Rudenkov avatar Apr 10 '20 21:04 Sergei-Rudenkov

Problem is that increment seems to be an operation that should be done on the backend efficiently. This requires storing the value as an int in the backend.

If you are using a serialiser that changes the values (e.g. JSON converts to str stored in the backend), then this obviously won't work.

We should put a warning or something in the docs, and maybe see if we can disable the increment() method if an inappropriate serialiser is being used (or maybe a fallback method could be used which just does set(key, get(key) + 1).

Dreamsorcerer avatar Jan 01 '23 23:01 Dreamsorcerer