From 1b052a3a0e4ea3e0fabcc07d0580e7b4b8d7af8e Mon Sep 17 00:00:00 2001 From: Bruno Clermont Date: Mon, 26 Nov 2012 16:25:00 +0800 Subject: [PATCH 1/3] catch error raised inside the settings code --- configurations/importer.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/configurations/importer.py b/configurations/importer.py index 6933eca..3deeb4a 100644 --- a/configurations/importer.py +++ b/configurations/importer.py @@ -148,9 +148,19 @@ class SettingsLoader(object): except Exception, err: raise ImproperlyConfigured("Couldn't load settings '%s.%s': %s" % (mod.__name__, self.name, err)) - for name, value in uppercase_attributes(obj).items(): + try: + attributes = uppercase_attributes(obj).items() + except Exception, err: + raise ImproperlyConfigured("Couldn't get items of settings '%s.%s': %s" % + (mod.__name__, self.name, err)) + for name, value in attributes: if callable(value): - value = value() - setattr(mod, name, value) + try: + value = value() + except Exception, err: + raise ImproperlyConfigured( + "Couldn't execute callable '%s' in '%s.%s': %s" % + value, mod.__name__, self.name, err)) + setattr(mod, name, value) setattr(mod, 'CONFIGURATION', '%s.%s' % (fullname, self.name)) return mod From 53bf1b5548c0c6448328f649e43de384661d64c0 Mon Sep 17 00:00:00 2001 From: Bruno Clermont Date: Mon, 26 Nov 2012 16:29:59 +0800 Subject: [PATCH 2/3] oups bad copy-paste --- configurations/importer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configurations/importer.py b/configurations/importer.py index 3deeb4a..7013392 100644 --- a/configurations/importer.py +++ b/configurations/importer.py @@ -160,7 +160,7 @@ class SettingsLoader(object): except Exception, err: raise ImproperlyConfigured( "Couldn't execute callable '%s' in '%s.%s': %s" % - value, mod.__name__, self.name, err)) + (value, mod.__name__, self.name, err)) setattr(mod, name, value) setattr(mod, 'CONFIGURATION', '%s.%s' % (fullname, self.name)) return mod From 41b8f3655c5bd58fc5b1ae874c2854aa8477612d Mon Sep 17 00:00:00 2001 From: Bruno Clermont Date: Mon, 26 Nov 2012 23:11:26 +0800 Subject: [PATCH 3/3] fix indentation --- configurations/importer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configurations/importer.py b/configurations/importer.py index 7013392..62b1dba 100644 --- a/configurations/importer.py +++ b/configurations/importer.py @@ -161,6 +161,6 @@ class SettingsLoader(object): raise ImproperlyConfigured( "Couldn't execute callable '%s' in '%s.%s': %s" % (value, mod.__name__, self.name, err)) - setattr(mod, name, value) + setattr(mod, name, value) setattr(mod, 'CONFIGURATION', '%s.%s' % (fullname, self.name)) return mod