@@ -123,7 +123,7 @@ def test_show_menu_num_queries(self):
123
123
"""
124
124
tpl = Template ("{% load menu_tags %}{% show_menu %}" )
125
125
tpl .render (context )
126
-
126
+
127
127
def test_show_menu_cache_key_leak (self ):
128
128
context = self .get_context ()
129
129
tpl = Template ("{% load menu_tags %}{% show_menu %}" )
@@ -132,7 +132,20 @@ def test_show_menu_cache_key_leak(self):
132
132
self .assertEqual (CacheKey .objects .count (), 1 )
133
133
tpl .render (context )
134
134
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
+
136
149
def test_only_active_tree (self ):
137
150
context = self .get_context ()
138
151
# test standard show_menu
0 commit comments