-
-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reading cache breaks with int-enums with redis-py >= 4.0 #595
Comments
Hello @syphar. To me it sounds very weird that I would recommend to do a test to be sure, forcing redis-py to version 3.x. It seems also pretty strange to me that you want to save an enum to cache, |
I get the debugability & speed points, security only if you assume your cache is compromised (but then the world is on fire anyways :) ). In our case "ease of use" wins. I would expect a cache with pickle to be able to cache every python object I throw at it. In our case we have a decorator that caches expensive method results no matter the arguments or return values ( similar to
I already did that, with 3.x it works, with >=4.0 it breaks.
In the end, we have enumeration types only since python 3.4, enumeration types for choices in Django only since 3.0. Looking at the ( I'm happy be be convinced otherwise :) ) |
I just wanted to let you know that I have tried and confirmed your bug, Thank you for raising the issue. |
Hello @syphar sorry for the delay, yes were right, I will add an option to force encoding, in that case the decoding if using |
Describe the bug
When trying to update our app from
redis-py==3.5.3
toredis-py==4.2.0
we stumbled onto a problem. While it only started breaking with the new redis-py version, I believe it's actually a bug here indjango-redis
. This also happens with any version ofredis-py>=4.0.2
.I'm happy to provide a PR if this is seen as a bug.
I see in
DefaultClient.encode
that we have special behaviour where everything thatisinstance(obj, int)
will not be passed through the serializer (pickle in our case) or the compressor. InDefaultClient.decode
we just tryint(value)
to bypass deserialization and decompression for these.The problem is: for
models.IntegerChoices
and an integer-enum (see example)instance(enum_variant, int) is True
. This then leads to a text representation of the enum being stored in redis (something like<Values1.CHOICE_1: 1>
), which of course cannot be converted back to an integer viaint()
. And also it cannot be decoded with pickle.The diff between 3.5.3 and 4.0.2 is huge ( redis/redis-py@3.5.3...v4.0.2 ) and I couldn't directly see why this worked before, but I believe our encode/decode mapping is in the wrong here.
To Reproduce
This is with a default django-redis setup.
With
models.IntegerChoices
:With a python standard int-enum:
Expected behavior
I would expect the enum-variant to be cached and returned as enum-variant.
Stack trace
I don't think we need this, I'm happy to provide one if needed.
Environment (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: