Skip to content

Commit 17e618b

Browse files
committed
Fixed typo, added test
1 parent 2e0dbd7 commit 17e618b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

cms/tests/menu.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def test_show_menu_num_queries(self):
123123
"""
124124
tpl = Template("{% load menu_tags %}{% show_menu %}")
125125
tpl.render(context)
126-
126+
127127
def test_show_menu_cache_key_leak(self):
128128
context = self.get_context()
129129
tpl = Template("{% load menu_tags %}{% show_menu %}")
@@ -132,7 +132,20 @@ def test_show_menu_cache_key_leak(self):
132132
self.assertEqual(CacheKey.objects.count(), 1)
133133
tpl.render(context)
134134
self.assertEqual(CacheKey.objects.count(), 1)
135-
135+
136+
def test_menu_keys_duplicate_truncates(self):
137+
"""
138+
When two objects with the same characteristics are present in the
139+
database, get_or_create truncates the database table to "invalidate"
140+
the cache, before retrying. This can happen after migrations, and since
141+
it's only cache, we don't want any propagation of errors.
142+
"""
143+
CacheKey.objects.create(language="fr", site=1, key="a")
144+
CacheKey.objects.create(language="fr", site=1, key="a")
145+
CacheKey.objects.get_or_create(language="fr", site=1, key="a")
146+
147+
self.assertEqual(CacheKey.objects.count(), 1)
148+
136149
def test_only_active_tree(self):
137150
context = self.get_context()
138151
# test standard show_menu

menus/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def get_or_create(self, **kwargs):
2323
except CacheKey.MultipleObjectsReturned:
2424
# Truncate the table, we don't want a funny cache object to cause
2525
# mayhem!
26-
CacheKey.object.all().delete()
26+
CacheKey.objects.all().delete()
2727
return super(CacheKeyManager, self).get_or_create(**kwargs)
2828

2929

0 commit comments

Comments
 (0)