Skip to content

Commit

Permalink
Change to a simpler model of limiting the maximum number of iterations.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebryant committed Aug 6, 2014
1 parent ebe5175 commit b6ce448
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions django_autoconfig/autoconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import logging
LOGGER = logging.getLogger(__name__)

MAX_ITERATIONS = 1000

class OrderingRelationship(object):
'''
This class defines a relationship between an element in a setting
Expand Down Expand Up @@ -121,12 +123,10 @@ def configure_settings(settings):
Given a settings object, run automatic configuration of all
the apps in INSTALLED_APPS.
'''
changes = 0
old_changes = None
num_apps = 0
old_num_apps = len(settings['INSTALLED_APPS'])
changes = 1
iterations = 0

while changes or old_changes is None:
while changes:
changes = 0
for app_name in settings['INSTALLED_APPS']:
if app_name in settings.get('AUTOCONFIG_DISABLED_APPS', ()):
Expand All @@ -151,15 +151,10 @@ def configure_settings(settings):
)
for relationship in getattr(module, 'RELATIONSHIPS', []):
changes += relationship.apply_changes(settings)
num_apps = len(settings['INSTALLED_APPS'])

if (
old_changes is not None and
changes >= old_changes and
num_apps == old_num_apps
):
if iterations >= MAX_ITERATIONS:
raise ImproperlyConfigured(
'Autoconfiguration could not reach a consistent state'
)
old_changes = changes
old_num_apps = num_apps
iterations += 1
LOGGER.debug("Autoconfiguration took %d iterations.", iterations)

0 comments on commit b6ce448

Please sign in to comment.