Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#20584 closed Bug (needsinfo)

Django's Memcached backend get_many() doesn't handle generators

Reported by: guyon.moree@… Owned by: nobody
Component: Core (Cache system) Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When the "keys" parameter to get_many() is a generator, the values will be lost in the zip function.

Here's a simplified code example:

def make_key(k):
	return k

user_ids = (11387, 1304318)

keys = ('user_%d' % x for x in user_ids)

new_keys = map(lambda x: make_key(x), keys)

m = dict(zip(new_keys, keys))

assert( m == {} )

I believe this is related to this zip() behaviour:

I encountered this bug when upgrading from django 1.3 to django 1.5.1

Change History (2)

comment:1 Changed 5 years ago by Baptiste Mispelon

Resolution: needsinfo
Status: newclosed


The code example shows the expected behavior of a generator: once you iterate over it, it's empty.

Can you describe the actual bug you're encountering in your django application?

The commit that added the line you linked to [1] was already included in 1.3 so your problem must be elsewhere.

I'm going to mark this as needsinfo. Please re-open the ticket with an example on how you trigger the issue from django.



comment:2 Changed 5 years ago by anonymous

Ah, I misunderstood the problem myself, makes sense now. It worked in a previous version because the generator was not exhausted there.

thanks a lot, makes sense now

Note: See TracTickets for help on using tickets.
Back to Top