Skip to content

Commit 7323c2b

Browse files
committed
Allow for less configuration. Thanks to jeromer & cyberdelia for the reports!
1 parent 0f427ee commit 7323c2b

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

haystack/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
raise ImproperlyConfigured('The HAYSTACK_CONNECTIONS setting is required.')
3535
if DEFAULT_ALIAS not in settings.HAYSTACK_CONNECTIONS:
3636
raise ImproperlyConfigured("The default alias '%s' must be included in the HAYSTACK_CONNECTIONS setting." % DEFAULT_ALIAS)
37-
for alias, connection in settings.HAYSTACK_CONNECTIONS.items():
38-
if 'ENGINE' not in connection:
39-
raise ImproperlyConfigured("You must specify a 'ENGINE' for connection '%s'" % alias)
4037

4138
# Load the connections.
4239
connections = loading.ConnectionHandler(settings.HAYSTACK_CONNECTIONS)

haystack/utils/loading.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,20 @@ def __init__(self, connections_info):
8282
self._connections = {}
8383
self._index = None
8484

85+
def ensure_defaults(self, alias):
86+
try:
87+
conn = self.connections_info[alias]
88+
except KeyError:
89+
raise ImproperlyConfigured("The key '%s' isn't an available connection." % alias)
90+
91+
if not conn.get('ENGINE'):
92+
conn['ENGINE'] = 'haystack.backends.simple_backend.SimpleEngine'
93+
8594
def __getitem__(self, key):
8695
if key in self._connections:
8796
return self._connections[key]
8897

89-
if not key in self.connections_info:
90-
raise ImproperlyConfigured("The key '%s' isn't an available connection." % key)
91-
98+
self.ensure_defaults(key)
9299
self._connections[key] = load_backend(self.connections_info[key]['ENGINE'])(using=key)
93100
return self._connections[key]
94101

0 commit comments

Comments
 (0)