Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#30713 closed Bug (invalid)

ListView queryset issue

Reported by: Dmitrij Strelnikov Owned by: nobody
Component: Database layer (models, ORM) Version: 2.2
Severity: Normal Keywords: queryset
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi guys,
is this intentional behaviour or not?

class SomeQuerySet(models.QuerySet):
    def active(self):
        print('active')
        data = cache.get(CACHE_KEY)
        if data is None:
            print('no cache')
            data = self.select_related('related').filter(date_expired__gte=timezone.localtime().now()).filter(
                some__is_active=True).order_by('-date_activated')
            cache.set(CACHE_KEY, data, 30)
        return data

class QSSomeListView(ListView):
    queryset = Some.objects.active()
class GetQSSomeListView(ListView):
    def get_queryset(self): 
        return Some.objects.active()

QSSomeListView never print anything from active() method on page access, and actually never hit cache. It print only active once at project startup.

GetQSSomeListView works as expected.

If its intentional, could you please explain / point me why so?
Thank you.

Change History (4)

comment:1 by Carlton Gibson, 5 years ago

Resolution: invalid
Status: newclosed

Please don't use the issue tracker as a secondary support channel. See TicketClosingReasons/UseSupportChannels.

comment:2 by Dmitrij Strelnikov, 5 years ago

Resolution: invalid
Status: closednew

Carlton, so you are telling this behaviour is not a bug?
It's not support question, if so I would use stack overflow instead.
Thanks

comment:3 by Claude Paroz, 5 years ago

Resolution: invalid
Status: newclosed

No, it's not a bug in Django. It's related to your active() method not being lazily evaluated. Please follow Carlton's advice.

comment:4 by Dmitrij Strelnikov, 5 years ago

thank you Claude, this was the thing I need to hear
have a great day

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