diff options
author | showard <showard@592f7852-d20e-0410-864c-8624ca9c26a4> | 2009-12-07 19:39:39 +0000 |
---|---|---|
committer | showard <showard@592f7852-d20e-0410-864c-8624ca9c26a4> | 2009-12-07 19:39:39 +0000 |
commit | 88ab7a5c67f1c3dece24be54ca4417be815ae2a6 (patch) | |
tree | d1999764a4d64aed8991f2cc591181ad9b53fdac /database | |
parent | eb393dfd9d5690ac87f05ff67eb3cf8aad15c618 (diff) |
Fix handling of database reconnects in the scheduler by enhancing the "django" database_connection backend and having the scheduler use it. This eliminates the duplicate connection that the scheduler was setting up -- now it uses only a single connection (the Django one).
Signed-off-by: Steve Howard <showard@google.com>
git-svn-id: svn://test.kernel.org/autotest/trunk@4000 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'database')
-rw-r--r-- | database/database_connection.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/database/database_connection.py b/database/database_connection.py index e1fcbe1a..e1e32225 100644 --- a/database/database_connection.py +++ b/database/database_connection.py @@ -101,16 +101,25 @@ class _SqliteBackend(_GenericBackend): class _DjangoBackend(_GenericBackend): def __init__(self): - from django.db import backend + from django.db import backend, connection, transaction super(_DjangoBackend, self).__init__(backend.Database) + self._django_connection = connection + self._django_transaction = transaction def connect(self, host=None, username=None, password=None, db_name=None): - from django.db import connection - self._connection = connection + self._connection = self._django_connection self._cursor = self._connection.cursor() + def execute(self, query, parameters=None): + try: + return super(_DjangoBackend, self).execute(query, + parameters=parameters) + finally: + self._django_transaction.commit_unless_managed() + + _BACKEND_MAP = { 'mysql': _MySqlBackend, 'sqlite': _SqliteBackend, |