diff --git a/wagtail/images/blocks.py b/wagtail/images/blocks.py index ca1b3d2169..dc9378c677 100644 --- a/wagtail/images/blocks.py +++ b/wagtail/images/blocks.py @@ -148,16 +148,9 @@ class ImageBlock(StructBlock): def bulk_to_python(self, values): values = list(values) - # The normal case: `values` is a list of dicts. This is the normal representation of this block. - if all(isinstance(value, dict) for value in values): - # `values` is a list of dicts containing `image`, `decorative` and `alt_text` keys - struct_values = super().bulk_to_python(values) - - # Else we are in a fallback for backwards compatibility with ImageChooserBlock - else: - # `values` might be a list of image IDs (as we might encounter if an ImageChooserBlock has been - # changed to an ImageBlock with no data migration) - # Or it could be a [None] if we are coming from an empty ImageChooserBlock + if values and all(value is None or isinstance(value, int) for value in values): + # `values` looks like a list of image IDs and/or None values (as we might encounter + # if an ImageChooserBlock has been changed to an ImageBlock with no data migration) image_values = self.child_blocks["image"].bulk_to_python(values) struct_values = [ @@ -169,6 +162,12 @@ class ImageBlock(StructBlock): for image in image_values ] + else: + # Treat `values` as the standard ImageBlock representation - a (possibly empty) list of + # dicts containing `image`, `decorative` and `alt_text` keys to be handled by the + # StructBlock superclass + struct_values = super().bulk_to_python(values) + return [ self._struct_value_to_image(struct_value) for struct_value in struct_values ]