开发者

Django command not noticing newly added data

I'm running from the interactive shell (via ./manage.py shell_plus)

开发者_StackOverflow中文版c = MyModel.objects.count()
while True
    assert MyModel.objects.count() == c
    sleep(1)

and then I go to the admin and add a new MyModel object. I would assume the assertion will fail, but it keeps getting the old count (not noticing the new record).

Do you know what is causing this? My first suspect is the cache system, but I don't know how to test it.

Do you know how to overcome this and allow the queries to notice the new records?

thanks in advance...


This sounds like an issue with transactions. You probably want to set your script to commit manually after each call to process_records.

See the transaction docs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜