Author: russellm Date: 2010-02-11 07:12:38 -0600 (Thu, 11 Feb 2010) New Revision: 12415
Modified: django/branches/releases/1.1.X/django/core/cache/backends/db.py django/branches/releases/1.1.X/tests/regressiontests/cache/tests.py Log: [1.1.X] Fixed #11483 -- Modified db cache backend to use db backend functions for date conversion, avoiding problems under Jython. Thanks to Leo Soto for the report and patch. Merge of r12411 from trunk. Modified: django/branches/releases/1.1.X/django/core/cache/backends/db.py =================================================================== --- django/branches/releases/1.1.X/django/core/cache/backends/db.py 2010-02-11 13:11:47 UTC (rev 12414) +++ django/branches/releases/1.1.X/django/core/cache/backends/db.py 2010-02-11 13:12:38 UTC (rev 12415) @@ -60,9 +60,11 @@ result = cursor.fetchone() if result and (mode == 'set' or (mode == 'add' and result[1] < now)): - cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % self._table, [encoded, str(exp), key]) + cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % self._table, + [encoded, connection.ops.value_to_db_datetime(exp), key]) else: - cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % self._table, [key, encoded, str(exp)]) + cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % self._table, + [key, encoded, connection.ops.value_to_db_datetime(exp)]) except DatabaseError: # To be threadsafe, updates/inserts are allowed to fail silently transaction.rollback_unless_managed() @@ -86,7 +88,8 @@ if self._cull_frequency == 0: cursor.execute("DELETE FROM %s" % self._table) else: - cursor.execute("DELETE FROM %s WHERE expires < %%s" % self._table, [str(now)]) + cursor.execute("DELETE FROM %s WHERE expires < %%s" % self._table, + [connection.ops.value_to_db_datetime(now)]) cursor.execute("SELECT COUNT(*) FROM %s" % self._table) num = cursor.fetchone()[0] if num > self._max_entries: Modified: django/branches/releases/1.1.X/tests/regressiontests/cache/tests.py =================================================================== --- django/branches/releases/1.1.X/tests/regressiontests/cache/tests.py 2010-02-11 13:11:47 UTC (rev 12414) +++ django/branches/releases/1.1.X/tests/regressiontests/cache/tests.py 2010-02-11 13:12:38 UTC (rev 12415) @@ -290,10 +290,6 @@ self.cache.add('key2', 'ham', 60*60*24*30 + 1) self.assertEqual(self.cache.get('key2'), 'ham') - self.cache.set_many({'key3': 'sausage', 'key4': 'lobster bisque'}, 60*60*24*30 + 1) - self.assertEqual(self.cache.get('key3'), 'sausage') - self.assertEqual(self.cache.get('key4'), 'lobster bisque') - class DBCacheTests(unittest.TestCase, BaseCacheTests): def setUp(self): # Spaces are used in the table name to ensure quoting/escaping is working -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.