diff options
author | Alexander Sulfrian <alexander.sulfrian@fu-berlin.de> | 2015-09-23 00:04:27 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander.sulfrian@fu-berlin.de> | 2015-09-23 19:44:14 +0200 |
commit | 7dfe4ea2f6c62ffb662085cb4d62a13b8e902ce1 (patch) | |
tree | c571e031668c16e682a86d9070940916bc7f52c8 /src/lib/Bcfg2 | |
parent | 0304e24b8011b96d5d9d3efad16d45f10a4c7709 (diff) | |
download | bcfg2-7dfe4ea2f6c62ffb662085cb4d62a13b8e902ce1.tar.gz bcfg2-7dfe4ea2f6c62ffb662085cb4d62a13b8e902ce1.tar.bz2 bcfg2-7dfe4ea2f6c62ffb662085cb4d62a13b8e902ce1.zip |
Replace close_connection() for newer django versions
django.db.close_connection() is deprecated in django1.7 (and removed in 1.8).
The new django.db.close_old_connections() does not seem to work like the old
one (see http://stackoverflow.com/a/32614137), so we replace it with an own
implementation.
Diffstat (limited to 'src/lib/Bcfg2')
-rw-r--r-- | src/lib/Bcfg2/Reporting/Storage/DjangoORM.py | 8 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Core.py | 9 |
2 files changed, 13 insertions, 4 deletions
diff --git a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py index c9aa169bf..7acd9e293 100644 --- a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py +++ b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py @@ -11,11 +11,11 @@ import Bcfg2.DBSettings from Bcfg2.Compat import md5 from Bcfg2.Reporting.Storage.base import StorageBase, StorageError from Bcfg2.Server.Plugin.exceptions import PluginExecutionError +import django from django.core import management from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned from django.db.models import FieldDoesNotExist from django.core.cache import cache -from django import db #Used by GetCurrentEntry import difflib @@ -383,8 +383,12 @@ class DjangoORM(StorageBase): finally: self.logger.debug("%s: Closing database connection" % self.__class__.__name__) - db.close_connection() + if django.VERSION[0] == 1 and django.VERSION[1] >= 7: + for connection in django.db.connections.all(): + connection.close() + else: + django.db.close_connection() def validate(self): """Validate backend storage. Should be called once when loaded""" diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index 4592688e7..87bbe7e1b 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -27,6 +27,7 @@ from Bcfg2.Server.Statistics import track_statistics try: from django.core.exceptions import ImproperlyConfigured + import django import django.conf HAS_DJANGO = True except ImportError: @@ -83,10 +84,14 @@ def close_db_connection(func): """ The decorated function """ rv = func(self, *args, **kwargs) if self._database_available: # pylint: disable=W0212 - from django import db self.logger.debug("%s: Closing database connection" % threading.current_thread().getName()) - db.close_connection() + + if django.VERSION[0] == 1 and django.VERSION[1] >= 7: + for connection in django.db.connections.all(): + connection.close() + else: + django.db.close_connection() return rv return inner |