Code

Opened 13 months ago

Closed 13 months ago

Last modified 13 months 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

Description

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

https://github.com/django/django/blob/master/django/core/cache/backends/memcached.py#L93

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: http://stackoverflow.com/questions/11210300/why-does-zip-drop-the-values-of-my-generator

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

Attachments (0)

Change History (2)

comment:1 Changed 13 months ago by bmispelon

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to needsinfo
  • Status changed from new to closed

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] https://github.com/django/django/commit/99d247f4cb0c22d19a4482a72a7a93584a5189da

comment:2 Changed 13 months 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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.