I have an issue where my production server displays incorrect results for a query (create and deletes were properly accounted for but not updates to existing fields which impacted the results). I assumed it was a date comparison issue and spent several hours debugging as I could not reproduce the error on dev. Eventually, I restarted gunicorn and the issue disappeared. It seems either postgresql or django was caching the queryset results. I have not set up caching so do not understand why this is happening.
I have 2 questions please:
- Who is doing the caching?
- How can I disable it? - I need to queryset to be evaluated each time it is called
Setup
Python 2.7
Django 1.7
PostgreSQL
Ubuntu
views.py Extract
class EventList(ListView, FilterMixin):
model = Listing
queryset = Listing.events.order_by('-from_date', )
models.py Extracts
class Listing(models.Model):
title = models.CharField(max_length=200, null=True)
to_date = models.DateTimeField(null=True, blank=True)
from_date = models.DateTimeField(null=True, blank=True)
events = EventManager()
event = models.ForeignKey('Event', related_name='listings', null=True, blank=True, on_delete=models.SET_NULL)
class EventManager(models.Manager):
def get_queryset(self):
now = arrow.now()
# Only listings which have events ending after today
qry = super(EventManager, self).get_queryset().filter(event__isnull=False).select_related('event').filter(to_date__gte=now.datetime)
return qry
SERIALIZABLEtransaction and seeing an old snapshot, in which case that's by design and your app asked for it.