diff options
| author | Guillermo BonvehĂ <gbonvehi@gmail.com> | 2020-06-20 04:33:24 -0300 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-06-22 07:10:16 +0200 |
| commit | b2e2489d807de360068f5a34c57d5345e526caf3 (patch) | |
| tree | 0cbcb9c32fc99680e66ab4bc08161df596b54167 /django | |
| parent | ac7f7eab0fad18fffc465bc4fdc092bcb2de2d80 (diff) | |
[3.1.x] Fixed #31728 -- Fixed cache culling when no key is found for deletion.
DatabaseCache._cull implementation could fail if no key was found to
perform a deletion in the table. This prevented the new cache key/value
from being correctly added.
Backport of f386454d1302b66d0eb331ed0ae9e4811e2f3a15 from master
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/cache/backends/db.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/django/core/cache/backends/db.py b/django/core/cache/backends/db.py index 33c79c5a14..acbe702255 100644 --- a/django/core/cache/backends/db.py +++ b/django/core/cache/backends/db.py @@ -267,9 +267,12 @@ class DatabaseCache(BaseDatabaseCache): cursor.execute( connection.ops.cache_key_culling_sql() % table, [cull_num]) - cursor.execute("DELETE FROM %s " - "WHERE cache_key < %%s" % table, - [cursor.fetchone()[0]]) + last_cache_key = cursor.fetchone() + if last_cache_key: + cursor.execute( + 'DELETE FROM %s WHERE cache_key < %%s' % table, + [last_cache_key[0]], + ) def clear(self): db = router.db_for_write(self.cache_model_class) |
