mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-17 19:51:11 +00:00
Catch empty non-StreamValues in get_prep_value. Fixes #4809
This commit is contained in:
parent
1803e69e9b
commit
17c564b7a0
4 changed files with 102 additions and 2 deletions
|
|
@ -243,8 +243,9 @@ class BaseStreamBlock(Block):
|
|||
], is_lazy=True)
|
||||
|
||||
def get_prep_value(self, value):
|
||||
if value is None:
|
||||
# treat None as identical to an empty stream
|
||||
if not value:
|
||||
# Falsy values (including None, empty string, empty list, and
|
||||
# empty StreamValue) become an empty stream
|
||||
return []
|
||||
else:
|
||||
# value is a StreamValue - delegate to its get_prep_value() method
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.15 on 2018-10-16 10:58
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wagtailcore', '0040_page_draft_title'),
|
||||
('tests', '0034_advertwithuuidcustomprimarykey'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='AddedStreamFieldWithEmptyListDefaultPage',
|
||||
fields=[
|
||||
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
bases=('wagtailcore.page',),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='AddedStreamFieldWithEmptyStringDefaultPage',
|
||||
fields=[
|
||||
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
bases=('wagtailcore.page',),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='AddedStreamFieldWithoutDefaultPage',
|
||||
fields=[
|
||||
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
bases=('wagtailcore.page',),
|
||||
),
|
||||
]
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.15 on 2018-10-16 11:00
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
import wagtail.core.blocks
|
||||
import wagtail.core.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tests', '0035_streamfieldmigrationmodels'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='addedstreamfieldwithemptylistdefaultpage',
|
||||
name='body',
|
||||
field=wagtail.core.fields.StreamField([('title', wagtail.core.blocks.CharBlock())], default=[]),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='addedstreamfieldwithemptystringdefaultpage',
|
||||
name='body',
|
||||
field=wagtail.core.fields.StreamField([('title', wagtail.core.blocks.CharBlock())], default=''),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='addedstreamfieldwithoutdefaultpage',
|
||||
name='body',
|
||||
field=wagtail.core.fields.StreamField([('title', wagtail.core.blocks.CharBlock())], default=''),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
||||
|
|
@ -1232,3 +1232,22 @@ class TabbedSettings(TestSetting):
|
|||
|
||||
class AlwaysShowInMenusPage(Page):
|
||||
show_in_menus_default = True
|
||||
|
||||
|
||||
# test for AddField migrations on StreamFields using various default values
|
||||
class AddedStreamFieldWithoutDefaultPage(Page):
|
||||
body = StreamField([
|
||||
('title', CharBlock())
|
||||
])
|
||||
|
||||
|
||||
class AddedStreamFieldWithEmptyStringDefaultPage(Page):
|
||||
body = StreamField([
|
||||
('title', CharBlock())
|
||||
], default='')
|
||||
|
||||
|
||||
class AddedStreamFieldWithEmptyListDefaultPage(Page):
|
||||
body = StreamField([
|
||||
('title', CharBlock())
|
||||
], default=[])
|
||||
|
|
|
|||
Loading…
Reference in a new issue