Configuration should be more forgiving to users who forget the trailing comma.
|Reported by:||mmarshall||Owned by:||adrian|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
It is really easy for users to forget the trailing comma in configuration settings that should be a tuple, resulting in weird errors. In order to help keep (new) users from getting frustrated, a string should be converted into a tuple for these settings.
Here is a patch to implement this:
Index: django/conf/settings.py =================================================================== --- django/conf/settings.py (revision 211) +++ django/conf/settings.py (working copy) @@ -29,9 +29,16 @@ except ImportError, e: raise EnvironmentError, "Could not import DJANGO_SETTINGS_MODULE '%s' (is it on sys.path?): %s" % (me.SETTINGS_MODULE, e) + +# a list of settings that should be converted into tuples if they are strings: +tuple_settings = ["INSTALLED_APPS","TEMPLATE_DIRS"] + for setting in dir(mod): if setting == setting.upper(): - setattr(me, setting, getattr(mod, setting)) + setting_value = getattr(mod, setting) + if setting in tuple_settings and type(setting_value) == str: + setting_value = (setting_value,) #In case the user forgot the comma. + setattr(me, setting, setting_value) # save DJANGO_SETTINGS_MODULE in case anyone in the future cares me.SETTINGS_MODULE = os.environ.get('DJANGO_SETTINGS_MODULE', '')
Note that I only put two entries in the tuple_settings list, as they are the only ones I know of. If there are more, they should be added.
Change History (2)
comment:1 Changed 10 years ago by anonymous
- Summary changed from jjjjConfiguration should be more forgiving to users who forget the trailing comma. to Configuration should be more forgiving to users who forget the trailing comma.