Handle None in ImageBlock.to_python

stable/6.3.x
Matt Westcott 2024-11-14 19:00:55 +00:00
rodzic 8c0ebb74a0
commit 645630828e
2 zmienionych plików z 8 dodań i 1 usunięć

Wyświetl plik

@ -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:

Wyświetl plik

@ -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([])