Comments (7)
By the way, I also tried to use encoding = None
when initializing MemcachedCache
(or RedisCache
) which works, but reading from the cache gives back bytes instead of strings (which is kind of annoying for most use-cases).
from aiocache.
Possibly the same as #515?
If not, then it'd probably be a good idea to create a test in a PR that reproduces the problem in CI.
from aiocache.
Possibly the same as #515?
Yeah, #515 is probably related, but UnicodeDecodeError
isn't raised when using PickleSerializer
instead of MsgPackSerializer
. See for yourself:
import asyncio
from aiocache import MemcachedCache
from aiocache.serializers import PickleSerializer
async def test():
cache = MemcachedCache(
serializer = PickleSerializer(),
)
await cache.set("test_case", { "key1": "test", "key2": 3 })
test_case = await cache.get("test_case")
print(test_case)
if __name__ == "__main__":
asyncio.run(test())
This code works fine.
If not, then it'd probably be a good idea to create a test in a PR that reproduces the problem in CI.
I'll try and add that.
from aiocache.
Acceptance tests for MsgPackSerializer
added (#836).
Please let me know if you have any insight on the issue, I'd be glad to help.
from aiocache.
I guess the design currently is that a serialiser should use strings? Though I don't understand how this serialiser got added when it doesn't work with anything... (the original tests don't actually test it with any caches: https://github.com/aio-libs/aiocache/pull/370/files#diff-14d53e5086ad36720b5073972f662da656b46898f2f8bdcdd06bb2fd9c2df9f5R86).
I guess the simple fix for now is to add .encode()
/.decode()
into the serialiser? So that it works with strings.
Then maybe a better refactoring can be done to avoid the overhead in future, though it's probably best we get #512 done before tackling that (which also requires some other tasks to be complete before that can be done: https://github.com/aio-libs/aiocache/milestone/8).
from aiocache.
I tried adding the following to MsgPackSerializer
's dumps
/loads
methods, but the UnicodeDecodeError
is still raised. Is that the workaround you had in mind?
diff --git a/aiocache/serializers/serializers.py b/aiocache/serializers/serializers.py
index 39a67e6..a3fcce9 100644
--- a/aiocache/serializers/serializers.py
+++ b/aiocache/serializers/serializers.py
@@ -184,7 +184,7 @@ class MsgPackSerializer(BaseSerializer):
:param value: obj
:returns: bytes
"""
- return msgpack.dumps(value)
+ return msgpack.dumps(value).decode("utf-8")
def loads(self, value):
"""
@@ -196,4 +196,4 @@ class MsgPackSerializer(BaseSerializer):
raw = False if self.encoding == "utf-8" else True
if value is None:
return None
- return msgpack.loads(value, raw=raw, use_list=self.use_list)
+ return msgpack.loads(value.encode("utf-8"), raw=raw, use_list=self.use_list)
from aiocache.
Yeah, that's what I was thinking. Thinking about it more, the problem is probably that we are decoding the raw bytes first, and that is actually in some binary form, so the decode operation won't work. I guess we'd need some way to disable the decoding (or make the decoding the responsibility of the serialiser maybe?). I suspect such changes won't be backwards compatible and will need to go to v1.
from aiocache.
Related Issues (20)
- Remove factory
- Tests folder being imported when installing version 0.12.0 HOT 1
- Merge cache implementation classes for each backend
- Library is unusable with redis older than 4.2.0 installed, even if redis isn't used HOT 2
- Type issues with VS Code + aiocache HOT 1
- Make it possible to run tests with a subset of dependencies HOT 5
- Cache key based on "self" in @cached decorator might not always be unique HOT 1
- [Question] Reuse decorator settings + Race Conditions
- "No module named 'redis.asyncio'" when trying to build with docker HOT 1
- Passing username to Redis in decorators HOT 1
- Redis cache decorator fail on Python3.11 HOT 2
- Create Multiple caches HOT 3
- New release HOT 1
- Preserve function signature with decorator HOT 3
- set_cache default does not work with plugins HOT 2
- Unsupported operand type(s) for +: 'float' and 'SimpleMemoryCache' HOT 3
- Error -2 connecting to redis server docker HOT 1
- Caching mutable function outputs HOT 3
- Test failures with Python 3.13.0b2 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiocache.