From b179c67860c6b834e5d35fadba4c905d8c6495d5 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 5 Mar 2025 20:02:23 -0500 Subject: [PATCH] [5.2.x] Clarified cryptic comment in django/core/cache/backends/redis.py. Backport of 9a729fb61add16d89a4b42b491aec2d22f1ae69a from main. --- django/core/cache/backends/redis.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/django/core/cache/backends/redis.py b/django/core/cache/backends/redis.py index eda8ac9457..bbf070a375 100644 --- a/django/core/cache/backends/redis.py +++ b/django/core/cache/backends/redis.py @@ -14,8 +14,9 @@ class RedisSerializer: self.protocol = pickle.HIGHEST_PROTOCOL if protocol is None else protocol def dumps(self, obj): - # Only skip pickling for integers, a int subclasses as bool should be - # pickled. + # For better incr() and decr() atomicity, don't pickle integers. + # Using type() rather than isinstance() matches only integers and not + # subclasses like bool. if type(obj) is int: return obj return pickle.dumps(obj, self.protocol)