mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-21 18:09:02 +01:00
Handle None in ImageBlock.to_python
This commit is contained in:
parent
0dd9b7dcb1
commit
58f849a294
@ -138,7 +138,7 @@ class ImageBlock(StructBlock):
|
||||
|
||||
def to_python(self, value):
|
||||
# For backward compatibility with ImageChooserBlock
|
||||
if isinstance(value, int):
|
||||
if value is None or isinstance(value, int):
|
||||
image = self.child_blocks["image"].to_python(value)
|
||||
struct_value = {"image": image, "decorative": False, "alt_text": None}
|
||||
else:
|
||||
|
@ -248,6 +248,13 @@ class TestImageBlock(TestImageChooserBlock):
|
||||
self.assertEqual(result.contextual_alt_text, "Sample text")
|
||||
self.assertFalse(result.decorative)
|
||||
|
||||
def test_to_python_with_none(self):
|
||||
# Like the test_to_python_with_int case, this can occur when a non-required
|
||||
# ImageChooserBlock has been changed to an ImageBlock
|
||||
block = ImageBlock(required=False)
|
||||
value = block.to_python(None)
|
||||
self.assertIsNone(value)
|
||||
|
||||
def test_bulk_to_python_with_empty_list(self):
|
||||
block = ImageBlock(required=False)
|
||||
result = block.bulk_to_python([])
|
||||
|
Loading…
Reference in New Issue
Block a user