From 5dfec4e23b4a3b81f8ec19bf0cf45147ad6b18e5 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Tue, 31 Dec 2013 16:22:42 +0100 Subject: [PATCH] Checked unicity of app config names when populating the app registry. This check will miss duplicates until the check for duplicate labels is added. Refs #21679. --- django/apps/registry.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/django/apps/registry.py b/django/apps/registry.py index c7c9a05679..317bde33fe 100644 --- a/django/apps/registry.py +++ b/django/apps/registry.py @@ -1,4 +1,4 @@ -from collections import defaultdict, OrderedDict +from collections import Counter, defaultdict, OrderedDict import os import sys import warnings @@ -79,8 +79,19 @@ class Apps(object): app_config = entry else: app_config = AppConfig.create(entry) + # TODO: check for duplicate app labels here (#21679). self.app_configs[app_config.label] = app_config + # Check for duplicate app names. + counts = Counter( + app_config.name for app_config in self.app_configs.values()) + duplicates = [ + name for name, count in counts.most_common() if count > 1] + if duplicates: + raise ImproperlyConfigured( + "Application names aren't unique, " + "duplicates: %s" % ", ".join(duplicates)) + # Load models. for app_config in self.app_configs.values(): all_models = self.all_models[app_config.label]