1

I'm wondering if the queryset manager in django-nonrel is broken, but I may just be missing something about how to use it. Here's my issue:

I've put together a simple blog using Django, but using djangoappengine. The model I use for the blog entries is called an Entry.

I have a view for deleting entries. Once an entry is deleted, it redirects to the home page, which lists all the remaining entries. The trouble is, the first time the redirect happens the entry which I just deleted remains there. If I refresh the page, it disappears from the list. The issue seems to be that even though I call Entry.objects.all() after deleting the entry, it is caching the values from earlier.

I moved the code over to a normal Django project and this bug didn't manifest, so I think it's to do with the queryset manager in django-nonrel.

I've tried doing lots of different things but I can't work out how requery the database. Here's some code for the view - I've simplified it so it doesn't even redirect, it just renders to response the entry_list with a call to Entry.objects.all(). Still the same problem.

def update_or_delete_object(request, *args, **kwargs):
    "A wrapper around the generic update_object view which allows a delete button too."
    if request.method == 'POST' and 'delete' in request.POST:
        #If they've just clicked the delete button
        object = get_object_or_404(Entry, pk=kwargs['object_id'])
        object.delete()
        return render_to_response('entry_list.html', {'object_list':Entry.objects.all()})
    return update_object(request, *args, **kwargs)

Any ideas?

seddonym
  • 16,304
  • 6
  • 66
  • 71
  • 2
    Could this be an issue with [eventual consistency](http://code.google.com/appengine/docs/python/datastore/hr/overview.html) in the high replication datastore? – Daniel Roseman Jan 31 '12 at 13:10
  • Yes I think you're right. But I can't work out how to handle that. Surely deleting an object and then redirecting to an updated list of objects is a fairly standard task? – seddonym Feb 06 '12 at 12:17
  • What you could do is remove the `Entry` object directly from the result before returning it: `if object in object_list: a.remove(object)`. A bit hackish, but then so is the result you're getting. – John Lyon Feb 29 '12 at 04:43

0 Answers0