KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm using the Django database models from a process that's not called from an HTTP request. The process is supposed to poll for new data every few seconds and do some processing on it. I have a loop that sleeps for a few seconds and then gets all unhandled data from the database. What I'm seeing is that after the first fetch, the process never sees any new data. I ran a few tests and it looks like Django is caching results, even though I'm building new QuerySets every time. To verify this, I did this from a Python shell: >>> MyModel.objects.count() 885 # (Here I added some more data from another process.) >>> MyModel.objects.count() 885 >>> MyModel.objects.update() 0 >>> MyModel.objects.count() 1025 As you can see, adding new data doesn't change the result count. However, calling the manager's update() method seems to fix the problem. I can't find any documentation on that update() method and have no idea what other bad things it might do. My question is, why am I seeing this caching behavior, which contradicts what Django docs say? And how do I prevent it from happening?
Tags (comma-separated)
Save Edits
Cancel