From 7dfe4ea2f6c62ffb662085cb4d62a13b8e902ce1 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 23 Sep 2015 00:04:27 +0200 Subject: 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. --- src/lib/Bcfg2/Server/Core.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/lib/Bcfg2/Server/Core.py') 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 -- cgit v1.2.3-1-g7c22