From 10e614a83c00933b50963e62419f992431807507 Mon Sep 17 00:00:00 2001 From: Taksh Date: Mon, 20 Apr 2026 16:54:14 +0530 Subject: [PATCH] Use try/hash to detect uncacheable args in process_cached process_cached.__call__ guarded the cache lookup with if not isinstance(args, collections.abc.Hashable): but `args` is always a tuple, and tuple itself is registered as Hashable. That check therefore passes even when the tuple contains an unhashable element (list, dict, set), so the subsequent `args in self.cache` lookup raises `TypeError: unhashable type: 'list'` - exactly the failure the comment "uncacheable. a list, for instance. better to not cache than blow up." claims to prevent. Switch to the `try: hash(args) / except TypeError:` pattern, which actually probes the container's element-wise hashability. Drop the now-unused `import collections`. --- openedx/core/lib/cache_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openedx/core/lib/cache_utils.py b/openedx/core/lib/cache_utils.py index dd80ceb9ccd1..6805243c135f 100644 --- a/openedx/core/lib/cache_utils.py +++ b/openedx/core/lib/cache_utils.py @@ -3,7 +3,6 @@ """ -import collections import functools import itertools import pickle @@ -125,7 +124,9 @@ def __init__(self, func): self.cache = {} def __call__(self, *args): - if not isinstance(args, collections.abc.Hashable): + try: + hash(args) + except TypeError: # uncacheable. a list, for instance. # better to not cache than blow up. return self.func(*args)