wagtail-deprecated / wagtail-react-streamfield

Powerful field for inserting multiple blocks with nesting. (NO LONGER MAINTAINED - See Wagtail 2.13 Release Notes)

Home Page:https://wagtail.github.io/react-streamfield/public/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Validation error when using nested StructBlocks

roodie opened this issue · comments

The problems is similar to the one I reported earlier. We have the following stucture defined for the 'participants' SteamField in our Event model (similar to #48):

class PersonRoleBlock(BaseBlockMixin, blocks.StructBlock):
    person = SnippetChooserBlock(target_model='members.Profile', required=True, label=_('Member'))
    instrument = SnippetChooserBlock(target_model='members.Instrument', required=False, label=_('Instrument'))
    role = blocks.CharBlock(required=False, label=_('Role (HU)'), help_text=_('If set, it overwrites the instrument'))
  
    class Meta:
        icon = 'user'
        closed = True

class RoleGroupBlock(BaseBlockMixin, blocks.StructBlock):
    title = blocks.CharBlock(required=False)
    participants = blocks.ListBlock(child_block=PersonRoleBlock(), required=True, label=_('Participants'))
    show_role = blocks.BooleanBlock(label=('Show roles/instruments'), required=False)

    class Meta:
        icon = 'user'
        closed = True

# line from the Event model
cast = StreamField(block_types=[
    ('rolegroup', RoleGroupBlock(label=_('Participant Group')))
],  blank=True, null=True)

If the editor adds a PersonRoleBlock element but forgets to select the profile for "person" field in the sub-block, an exception occurs:

'str' object has no attribute 'as_data'

Full stracktrace:

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail/admin/urls/__init__.py" in wrapper
  102.             return view_func(request, *args, **kwargs)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail/admin/decorators.py" in decorated_view
  34.             return view_func(request, *args, **kwargs)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail/admin/views/pages.py" in edit
  545.         'has_unsaved_changes': has_unsaved_changes,

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/shortcuts.py" in render
  36.     content = loader.render_to_string(template_name, context, request, using=using)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/loader.py" in render_to_string
  62.     return template.render(context, request)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/backends/django.py" in render
  61.             return self.template.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  171.                     return self._render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/test/utils.py" in instrumented_test_render
  96.     return self.nodelist.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  150.             return compiled_parent._render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/test/utils.py" in instrumented_test_render
  96.     return self.nodelist.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  150.             return compiled_parent._render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/test/utils.py" in instrumented_test_render
  96.     return self.nodelist.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  150.             return compiled_parent._render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/test/utils.py" in instrumented_test_render
  96.     return self.nodelist.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  150.             return compiled_parent._render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/test/utils.py" in instrumented_test_render
  96.     return self.nodelist.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  150.             return compiled_parent._render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/test/utils.py" in instrumented_test_render
  96.     return self.nodelist.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  62.                 result = block.nodelist.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  62.                 result = block.nodelist.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  987.             output = self.filter_expression.resolve(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in resolve
  671.                 obj = self.var.resolve(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in resolve
  796.             value = self._resolve_lookup(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in _resolve_lookup
  858.                             current = current()

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail/admin/edit_handlers.py" in render_form_content
  252.         return mark_safe(self.render_as_object() + self.render_missing_fields())

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail/admin/edit_handlers.py" in render_as_object
  220.         return self.render()

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail/admin/edit_handlers.py" in render
  324.             'self': self

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/loader.py" in render_to_string
  62.     return template.render(context, request)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/backends/django.py" in render
  61.             return self.template.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  171.                     return self._render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/test/utils.py" in instrumented_test_render
  96.     return self.nodelist.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/defaulttags.py" in render
  209.                     nodelist.append(node.render_annotated(context))

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  987.             output = self.filter_expression.resolve(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in resolve
  671.                 obj = self.var.resolve(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in resolve
  796.             value = self._resolve_lookup(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in _resolve_lookup
  858.                             current = current()

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail/admin/edit_handlers.py" in render_as_object
  220.         return self.render()

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail/admin/edit_handlers.py" in render
  324.             'self': self

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/loader.py" in render_to_string
  62.     return template.render(context, request)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/backends/django.py" in render
  61.             return self.template.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  171.                     return self._render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/test/utils.py" in instrumented_test_render
  96.     return self.nodelist.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/defaulttags.py" in render
  209.                     nodelist.append(node.render_annotated(context))

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  987.             output = self.filter_expression.resolve(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in resolve
  671.                 obj = self.var.resolve(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in resolve
  796.             value = self._resolve_lookup(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in _resolve_lookup
  858.                             current = current()

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail/admin/edit_handlers.py" in render_as_object
  482.             'field': self.bound_field,

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/loader.py" in render_to_string
  62.     return template.render(context, request)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/backends/django.py" in render
  61.             return self.template.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  171.                     return self._render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/test/utils.py" in instrumented_test_render
  96.     return self.nodelist.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  188.             return template.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  173.                 return self._render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/test/utils.py" in instrumented_test_render
  96.     return self.nodelist.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  53.                 result = self.nodelist.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in render
  987.             output = self.filter_expression.resolve(context)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/django/template/base.py" in resolve
  698.                 new_obj = func(obj, *arg_vals)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail/admin/templatetags/wagtailadmin_tags.py" in render_with_errors
  248.             errors=bound_field.errors

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail_react_streamfield/widgets.py" in render_with_errors
  94.         streamfield_config = self.get_streamfield_config(value, errors=errors)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail_react_streamfield/widgets.py" in get_streamfield_config
  89.             'value': self.block_def.prepare_value(value, errors=errors),

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail_react_streamfield/monkey_patch.py" in inner
  19.             return new_method(*args, **kwargs)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail_react_streamfield/blocks/stream_block.py" in prepare_value
  70.                                                    errors=child_errors),

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail_react_streamfield/monkey_patch.py" in inner
  19.             return new_method(*args, **kwargs)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail_react_streamfield/blocks/struct_block.py" in prepare_value
  74.                 'value': child_block.prepare_value(child_value, errors=errors),

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail_react_streamfield/monkey_patch.py" in inner
  19.             return new_method(*args, **kwargs)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail_react_streamfield/blocks/list_block.py" in prepare_value
  64.                                                       errors=child_errors)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail_react_streamfield/blocks/block.py" in get_instance_html
  33.         non_block_errors = get_non_block_errors(errors)

File "/var/www/virtualenv_wagtail/lib/python3.6/site-packages/wagtail_react_streamfield/widgets.py" in get_non_block_errors
  51.     errors_data = errors.as_data()

Exception Type: AttributeError at /admin/pages/2016/edit/
Exception Value: 'str' object has no attribute 'as_data'

Django: 2.2.1
Wagtail: 2.3.2
React-streamfield: 1.3.4

Yes, I experienced it as well for the first time literally 1 hour ago!
I’m working on it.

I can confirm, this works now as expected!