Opened 4 years ago
Closed 4 years ago
Last modified 4 years ago
#20584 closed Bug (needsinfo)
Django's Memcached backend get_many() doesn't handle generators
Description
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 4 years ago by
comment:2 Changed 4 years ago by
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
Hi,
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.
Thanks.
[1]