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

StreamFields on Snippets do not persist

chrisbethelepb opened this issue · comments

If you create a Wagtail snippet model like so:

from wagtail.admin.edit_handlers import StreamFieldPanel, FieldPanel
from wagtail.core import blocks
from wagtail.snippets.models import register_snippet
from wagtail.core.fields import StreamField
from django.db import models


@register_snippet
class TestSnippet(models.Model):
    name = models.CharField(max_length=255)

    link = StreamField([
        ('page_link', blocks.PageChooserBlock(required=True, help_text='Add Link to Page')),
        ('url_link', blocks.URLBlock(required=True, help_text='Add URL')),
        ('text', blocks.CharBlock(required=True))
    ], default=None)

    panels = [
        FieldPanel('name'),
        StreamFieldPanel('link'),
    ]

    def __str__(self):
        return self.name

The Snippet registers and is added to the Wagtail admin interface. However, with the wagtail_react_streamfield app installed, any contents placed in the StreamField are not persisted.

The validation runs as expected -- if you mark a field as required as shown in the example, not filling out the field will return an error as expected. However, once the validation rules are met, the JSON data for the StreamField is persisted as an empty array.

Validation working as expected:
Screen Shot 2020-01-09 at 9 31 28 AM

Attempting to save this with valid data appears to be successful, as you would expect:
Screen Shot 2020-01-09 at 9 32 05 AM
Screen Shot 2020-01-09 at 9 32 32 AM

However, attempting to edit this newly saved snippet shows that the StreamField is empty:
Screen Shot 2020-01-09 at 9 33 17 AM
... and the database entry reflects this:
Screen Shot 2020-01-09 at 9 34 21 AM

If I do not enable the wagtail_react_streamfield app, this persists as expected.

Django 2.2.9, Wagtail 2.7.1, wagtail-react-streamfield 1.3.5

Thank you for your detailed report and your patience, @chrisbethelepb.

That’s a good point, I actually didn’t think at all about StreamFields inside snippets. And nobody ever talked to me about it apart from you, so it’s great to see that it is mostly working, apart from the most important part, saving 😅

That’s quite critical as there is no way to selectively enable React StreamField per model, so using wagtail-react-streamfield on a project can lead to a data losses on a few projects like yours.

I’m looking into it this afternoon to find what’s going on and find a solution.

I actually could not reproduce the issue, I successfully saved a complex block inside a snippet in a modified version of bakerydemo as you can see in the screenshot below.

Did you properly check that the JS loaded was up to date by using CTRL+F5?
Anyway, I’m marking this issue as invalid and closing it for now, please reopen it if you experience again in newer versions.

image