Skip to content

Commit

Permalink
Fixup segmentation: skip non-required empty bool fields (#514)
Browse files Browse the repository at this point in the history
Issue: https://git.wechange.de/gl/code/portals/s4f/-/issues/32

* Fixup segmentation: skip non-required empty bool fields

Also fix the empty value check for "0".

* Add empty list to empty_field_values
  • Loading branch information
2e2a authored Jan 30, 2025
1 parent 11f781c commit 142df35
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions cosinnus/api_frontend/serializers/dynamic_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,10 @@ def validate(self, attrs):
try:
field_value = formfield.to_python(field_value)
# skip non-required, empty fields
if (
not field_value
and not isinstance(field_value, bool)
and (
not field_options.required
or (self.all_fields_optional and field_name not in dynamic_field_attr_dict)
)
emtpy_field_values = [None, '', False, []]
if field_value in emtpy_field_values and (
not field_options.required
or (self.all_fields_optional and field_name not in dynamic_field_attr_dict)
):
continue
formfield.validate(field_value)
Expand Down

0 comments on commit 142df35

Please sign in to comment.