﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20129	Storing a related queryset in attribute clears session	Francesc Ortiz	nobody	"Hi, I don't know if I am missing something important, but I have a very weird behavior with this piece of code that took me some hours to find out:

{{{
class ModelA(models.Model, AbstractModel)
    ...

    def items():
        try:
            return self._items_qs_cache
        except AttributeError:
            current_minute = return datetime.now().replace(second=0, microsecond=0)
            self._items_qs_cache = self.children_set.filter(published=True, publish_date__lte=current_minute)
            return self_items_qs_cache

    parent = models.ForeignKey('self', blank=True, null=True, verbose_name=_('parent'), related_name='children_set')
}}}

Calling the items() function clears the session!

But, if instead you replace the following line

{{{
self._items_qs_cache = self.children_set.filter(published=True, publish_date__lte=current_minute)
}}}

with the following equivalent one

{{{
self._items_qs_cache = Model.objects.filter(published=True, publish_date__lte=current_minute, parent=self)
}}}

The session does not get cleared.

Is this a django bug or am I missing somthing.

Thank you,

"	Bug	closed	Database layer (models, ORM)	1.5	Normal	worksforme		pegler@… bmispelon@…	Unreviewed	0	0	0	0	0	0
