Skip to content

Commit 67c0733

Browse files
authored
Avoid server error in FlexibleImageWidget validation (#4381)
Fix error in `FlexibleImageWidget.decompress()` due to unexpected value. This now properly raises a "field required" validation error on the field. The possible data returned from the possible widgets of `FlexibleImageWidget` was not completely tested. This adds a test where we extract the form data from the response of the flexible image widget for each of the possible options the user can select. Closes #4312
1 parent ec46c8a commit 67c0733

4 files changed

Lines changed: 256 additions & 154 deletions

File tree

app/grandchallenge/cases/widgets.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,17 @@ def __init__(
6363
)
6464
super().__init__(widgets, attrs)
6565

66-
def decompress(self, value):
66+
def decompress(self, value): # noqa: C901
6767
if not value:
6868
return [None, None]
6969

7070
if isinstance(value, (list, tuple)):
7171
if len(value) == 1:
7272
item = value[0]
73+
if item == "":
74+
return [None, None]
75+
if not item:
76+
raise RuntimeError("Unexpected value")
7377
if item in ImageWidgetChoices.names:
7478
return [None, None]
7579
if Image.objects.filter(pk=item).exists():

0 commit comments

Comments
 (0)