Ticket #23070: 23070.diff

File 23070.diff, 2.0 KB (added by Hiroki Kiyohara, 10 years ago)
  • django/views/debug.py

    diff --git a/django/views/debug.py b/django/views/debug.py
    index efb3079..f6bf5b4 100644
    a b from django.template import Template, Context, TemplateDoesNotExist  
    1313from django.template.defaultfilters import force_escape, pprint
    1414from django.utils.datastructures import MultiValueDict
    1515from django.utils.html import escape
    16 from django.utils.encoding import force_bytes, smart_text
     16from django.utils.encoding import force_bytes, force_text, smart_text
    1717from django.utils.module_loading import import_string
    1818from django.utils import six
    1919
    def cleanse_setting(key, value):  
    5050        cleansed = value
    5151
    5252    if callable(cleansed):
    53         cleansed.do_not_call_in_templates = True
     53        # For fixing #21345 and #23070
     54        cleansed = force_text(cleansed)
    5455
    5556    return cleansed
    5657
  • tests/view_tests/tests/test_debug.py

    diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py
    index b66bdac..f799325 100644
    a b class ExceptionReporterFilterTests(TestCase, ExceptionReportTestMixin):  
    652652            response = self.client.get('/raises500/')
    653653            self.assertNotContains(response, "This should not be displayed", status_code=500)
    654654
     655    def test_callable_settings_forbidding_to_set_attributes(self):
     656        """
     657        Callable settings which forbid to set attributes should not break
     658        the debug page (#23070).
     659        """
     660        class CallableSettingWithSlots(object):
     661            __slots__ = []
     662
     663            def __call__(self):
     664                return "This should not be displayed"
     665
     666        with self.settings(DEBUG=True, WITH_SLOTS=CallableSettingWithSlots()):
     667            response = self.client.get('/raises500/')
     668            self.assertNotContains(response, "This should not be displayed", status_code=500)
     669
    655670    def test_dict_setting_with_non_str_key(self):
    656671        """
    657672        A dict setting containing a non-string key should not break the
Back to Top