Skip to content

Commit

Permalink
🐛 [#4772] Add migration to set select dataType to string
Browse files Browse the repository at this point in the history
because Select components did not have a dataType set, formio tries to cast it to other types if possible, which causes issues when submitting the data to the backend. For that reason we set the value to string to avoid this unwanted normalization
  • Loading branch information
stevenbal committed Nov 11, 2024
1 parent 4c53505 commit 076c42b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/openforms/formio/migration_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ def fix_multiple_empty_default_value(component: Component) -> bool:
return False


def set_datatype_string(component: Component):
# https://github.com/open-formulieren/open-forms/issues/4772
if component.get("dataType") != "string":
component["dataType"] = "string"
return True
return False

Check warning on line 216 in src/openforms/formio/migration_converters.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/formio/migration_converters.py#L214-L216

Added lines #L214 - L216 were not covered by tests


def convert_simple_conditionals(configuration: JSONObject) -> bool:
config_modified = False

Expand Down Expand Up @@ -350,6 +358,7 @@ def fix_empty_default_value(component: Component) -> bool:
"select": {
"set_openforms_datasrc": set_openforms_datasrc,
"fix_multiple_empty_default_value": fix_multiple_empty_default_value,
"set_datatype_string": set_datatype_string,
},
"selectboxes": {"set_openforms_datasrc": set_openforms_datasrc},
"currency": {
Expand Down
1 change: 1 addition & 0 deletions src/openforms/formio/typing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class Component(TypedDict):
prefill: NotRequired[PrefillConfiguration]
openForms: NotRequired[OpenFormsConfig]
autocomplete: NotRequired[str]
dataType: NotRequired[str]


class FormioConfiguration(TypedDict):
Expand Down
16 changes: 16 additions & 0 deletions src/openforms/forms/migrations/0104_select_datatype_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.16 on 2024-11-11 12:00

from django.db import migrations

from openforms.forms.migration_operations import ConvertComponentsOperation


class Migration(migrations.Migration):

dependencies = [
("forms", "0103_remove_formvariable_prefill_config_empty_or_complete_and_more"),
]

operations = [
ConvertComponentsOperation("select", "set_datatype_string"),
]

0 comments on commit 076c42b

Please sign in to comment.