Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions django/core/cache/backends/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ def __init__(self, protocol=None):
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool is in an int subclass, so isinstance(obj, int) won't work here. This is what we were trying to explain here 🤔

Copy link
Contributor

@nessita nessita Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest something like:

# Only skip pickling for plain integers. Subclasses of `int`, including `bool`, should be
# pickled.

# 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)
Expand Down