Commit 750d4487 by Renzo Lucioni

Avoid passing a generator expression to cache.get_many()

Generator expressions passed to the memcached backend's implementation of get_many() are exhausted prematurely. This results in KeyErrors when the backend tries to map keys returned by memcached back to keys passed by application code.

See https://github.com/django/django/blob/stable/1.8.x/django/core/cache/backends/memcached.py/#L99.

LEARNER-382
parent 5cf828a7
...@@ -53,7 +53,7 @@ def get_programs(uuid=None): ...@@ -53,7 +53,7 @@ def get_programs(uuid=None):
if not uuids: if not uuids:
logger.warning('Program UUIDs are not cached.') logger.warning('Program UUIDs are not cached.')
programs = cache.get_many(PROGRAM_CACHE_KEY_TPL.format(uuid=uuid) for uuid in uuids) programs = cache.get_many([PROGRAM_CACHE_KEY_TPL.format(uuid=uuid) for uuid in uuids])
programs = list(programs.values()) programs = list(programs.values())
missing_uuids = set(uuids) - set(program['uuid'] for program in programs) missing_uuids = set(uuids) - set(program['uuid'] for program in programs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment