jazzband / wagtailmenus

An app to help you manage and render menus in your Wagtail projects more effectively
MIT License
398 stars 138 forks source link

`help_text` with `mark_safe_lazy` breaks the admin panel: `TypeError at /admin/wagtailmenus/flatmenu/create/: __str__ returned non-string (type __proxy__)` #430

Closed janbaykara closed 2 years ago

janbaykara commented 2 years ago

It seems that when help_text wrapped in mark_safe_lazy code is called, it throws an error in the wagtail admin modules: https://github.com/jazzband/wagtailmenus/blob/100d90c27e0b2bcd828a4667e86deae49c4842d0/wagtailmenus/models/menus.py#L1167-L1172

Environment

Request Method: GET Request URL: http://localhost:8000/admin/wagtailmenus/flatmenu/create/

Wagtail Version: 4.0.2 Django Version: 4.1.1 Python Version: 3.9.12

Logs

Template error:
In template /home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/wagtail/admin/templates/wagtailadmin/shared/field.html, error at line 77
   __str__ returned non-string (type __proxy__)
   67 : 
   68 :             {% if show_add_comment_button %}
   69 :                 <button class="w-field__comment-button w-field__comment-button--add" type="button" data-component="add-comment-button" data-comment-add aria-label="{% trans 'Add comment' %}" {% if label_for %}aria-describedby="{{ label_id }}"{% endif %}>
   70 :                     {% icon name="comment-add" %}
   71 :                     {% icon name="comment-add-reversed" %}
   72 :                 </button>
   73 :             {% endif %}
   74 :         </div>
   75 : 
   76 :         <div {% if help_text_id %}id="{{ help_text_id }}"{% endif %} data-field-help>
   77 :              {% firstof help_text field.help_text as help_text_value %} 
   78 :             {% if help_text_value %}
   79 :                 <div class="help">{{ help_text_value }}</div>
   80 :             {% endif %}
   81 :         </div>
   82 :     </div>
   83 : </div>
   84 : 
Full stack ``` Traceback (most recent call last): File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/core/handlers/base.py", line 220, in _get_response response = response.render() File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/wagtail/admin/auth.py", line 197, in overridden_render return render() File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/response.py", line 114, in render self.content = self.rendered_content File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/response.py", line 92, in rendered_content return template.render(context, self._request) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/backends/django.py", line 62, in render return self.template.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 175, in render return self._render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/test/utils.py", line 111, in instrumented_test_render return self.nodelist.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/loader_tags.py", line 157, in render return compiled_parent._render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/test/utils.py", line 111, in instrumented_test_render return self.nodelist.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/loader_tags.py", line 157, in render return compiled_parent._render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/test/utils.py", line 111, in instrumented_test_render return self.nodelist.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/loader_tags.py", line 157, in render return compiled_parent._render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/test/utils.py", line 111, in instrumented_test_render return self.nodelist.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/loader_tags.py", line 157, in render return compiled_parent._render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/test/utils.py", line 111, in instrumented_test_render return self.nodelist.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/loader_tags.py", line 157, in render return compiled_parent._render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/test/utils.py", line 111, in instrumented_test_render return self.nodelist.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/loader_tags.py", line 63, in render result = block.nodelist.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/loader_tags.py", line 63, in render result = block.nodelist.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/loader_tags.py", line 63, in render result = block.nodelist.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1064, in render output = self.filter_expression.resolve(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 715, in resolve obj = self.var.resolve(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 847, in resolve value = self._resolve_lookup(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 914, in _resolve_lookup current = current() File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/wagtail/admin/panels.py", line 392, in render_form_content return mark_safe(self.render_html() + self.render_missing_fields()) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/wagtail/admin/ui/components.py", line 20, in render_html return template.render(context_data) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/backends/django.py", line 62, in render return self.template.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 175, in render return self._render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/test/utils.py", line 111, in instrumented_test_render return self.nodelist.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/defaulttags.py", line 238, in render nodelist.append(node.render_annotated(context)) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1064, in render output = self.filter_expression.resolve(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 715, in resolve obj = self.var.resolve(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 847, in resolve value = self._resolve_lookup(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 914, in _resolve_lookup current = current() File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/wagtail/admin/ui/components.py", line 20, in render_html return template.render(context_data) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/backends/django.py", line 62, in render return self.template.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 175, in render return self._render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/test/utils.py", line 111, in instrumented_test_render return self.nodelist.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/defaulttags.py", line 238, in render nodelist.append(node.render_annotated(context)) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/wagtail/admin/templatetags/wagtailadmin_tags.py", line 948, in render children = self.nodelist.render(context) if self.nodelist else "" File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/library.py", line 237, in render output = self.func(*resolved_args, **resolved_kwargs) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/wagtail/admin/templatetags/wagtailadmin_tags.py", line 876, in component return obj.render_html(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/wagtail/admin/ui/components.py", line 20, in render_html return template.render(context_data) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/backends/django.py", line 62, in render return self.template.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 175, in render return self._render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/test/utils.py", line 111, in instrumented_test_render return self.nodelist.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/defaulttags.py", line 238, in render nodelist.append(node.render_annotated(context)) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/library.py", line 237, in render output = self.func(*resolved_args, **resolved_kwargs) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/wagtail/admin/templatetags/wagtailadmin_tags.py", line 876, in component return obj.render_html(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/wagtail/admin/ui/components.py", line 20, in render_html return template.render(context_data) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/backends/django.py", line 62, in render return self.template.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 175, in render return self._render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/test/utils.py", line 111, in instrumented_test_render return self.nodelist.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/loader_tags.py", line 208, in render return template.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 177, in render return self._render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/test/utils.py", line 111, in instrumented_test_render return self.nodelist.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/defaulttags.py", line 151, in render first = render_value_in_context(value, context) File "/home/vscode/.local/share/virtualenvs/workspace-dqq3IVyd/lib/python3.9/site-packages/django/template/base.py", line ```
1047, in render_value_in_context
    value = str(value)

Exception Type: TypeError at /admin/wagtailmenus/flatmenu/create/
Exception Value: __str__ returned non-string (type __proxy__)\\

Local Vars

Variable Value
context [{'True': True, 'False': False, 'None': None}, {'self': <BoundPanel 'max_levels' with model=<class 'wagtailmenus.models.menus.FlatMenu'> instance= () request=<WSGIRequest: GET '/admin/wagtailmenus/flatmenu/create/'> form=FlatMenuForm>, 'field': <django.forms.boundfield.BoundField object at 0x7f1df03a1640>, 'rendered_field': '', 'help_text': 'The maximum number of levels to display when rendering this menu. The value can be overidden by supplying a different max_levels value to the {% flat_menu %} tag in your templates.', 'help_text_id': 'panel-child-settings-child-render_settings-child-max_levels-helptext', 'error_message_id': 'panel-child-settings-child-render_settings-child-max_levels-errors', 'show_add_comment_button': True}]
value 'The maximum number of levels to display when rendering this menu. The value can be overidden by supplying a different max_levels value to the {% flat_menu %} tag in your templates.'
janbaykara commented 2 years ago

When I removed these mark_safe_lazy help_text properties, I'm able to load the page without fail.

janbaykara commented 2 years ago

Noted in https://github.com/jazzband/wagtailmenus/issues/428#issuecomment-1255606076

janbaykara commented 2 years ago

PR at #429