Commit c1b24083 by Luke Plant

Fixed bug with caching that was causing a test to fail.

Running Article.clear_cache() on deleting isn't enough to properly clear the
cache.  This is because get_cache_key() can return different values - so if
you 1) create an article 2) then modify it 3) then delete, the cache of
content after 1) is not cleared by Article.clear_cache() after 3).

Therefore, when saving, we also clear the instance cache. This is more
robust, and means we also don't have to explicitly delete Articles in test
tearDown.

This bug shows up particularly in tests, due to the increased possibility of
IDs being re-used.
parent 844bbd4a
...@@ -329,7 +329,7 @@ def _clear_ancestor_cache(article): ...@@ -329,7 +329,7 @@ def _clear_ancestor_cache(article):
ancestor.article.clear_cache() ancestor.article.clear_cache()
def on_article_save_clear_cache(instance, **kwargs): def on_article_save_clear_cache(instance, **kwargs):
_clear_ancestor_cache(instance) on_article_delete_clear_cache(instance, **kwargs)
post_save.connect(on_article_save_clear_cache, Article) post_save.connect(on_article_save_clear_cache, Article)
def on_article_delete_clear_cache(instance, **kwargs): def on_article_delete_clear_cache(instance, **kwargs):
......
...@@ -30,12 +30,6 @@ class ArticleTestBase(WebTestBase): ...@@ -30,12 +30,6 @@ class ArticleTestBase(WebTestBase):
'summary': 'why edited', 'summary': 'why edited',
'title': 'wiki test'} 'title': 'wiki test'}
def tearDown(self):
super(ArticleTestBase, self).tearDown()
# clear Article cache before the next test
from wiki.models import Article
Article.objects.all().delete()
def get_by_path(self, path): def get_by_path(self, path):
"""Get the article response for the path. """Get the article response for the path.
Example: self.get_by_path("Level1/Slug2/").title Example: self.get_by_path("Level1/Slug2/").title
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment