Skip to content

Commit f7f0c92

Browse files
committed
Use db.close_old_connections instead of close_connection
Django 1.8 removed the `db.close_connection` method. Thanks to Alfredo Armanini (@phingage) for the patch
1 parent 9cfa5a6 commit f7f0c92

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

AUTHORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,5 @@ Thanks to
100100
* Phill Tornroth (phill-tornroth) for several patches improving UnifiedIndex and ElasticSearch support
101101
* Philippe Luickx (philippeluickx) for documenting how to provide backend-specific facet options
102102
* Felipe Prenholato (@chronossc) for a patch making it easy to exclude documents from indexing using custom logic
103+
* Alfredo Armanini (@phingage) for a patch fixing compatibility with database API changes in Django 1.8
104+

haystack/management/commands/update_index.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
from datetime import timedelta
99
from optparse import make_option
1010

11-
from django import db
11+
try:
12+
from django.db import close_old_connections
13+
except ImportError:
14+
# This can be removed when we drop support for Django 1.7 and earlier:
15+
from django.db import close_connection as close_old_connections
16+
1217
from django.core.management.base import LabelCommand
1318
from django.db import reset_queries
1419

@@ -49,7 +54,7 @@ def worker(bits):
4954
# out connections (via ``... = {}``) destroys in-memory DBs.
5055
if 'sqlite3' not in info['ENGINE']:
5156
try:
52-
db.close_connection()
57+
close_old_connections()
5358
if isinstance(connections._connections, dict):
5459
del(connections._connections[alias])
5560
else:
@@ -206,7 +211,7 @@ def update_backend(self, label, using):
206211
# workers resetting connections leads to references to models / connections getting
207212
# stale and having their connection disconnected from under them. Resetting before
208213
# the loop continues and it accesses the ORM makes it better.
209-
db.close_connection()
214+
close_old_connections()
210215

211216
qs = index.build_queryset(using=using, start_date=self.start_date,
212217
end_date=self.end_date)

0 commit comments

Comments
 (0)