From 076c42b29408f8954cf1c2fa20f400421e98c674 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Mon, 11 Nov 2024 13:03:26 +0100 Subject: [PATCH] :bug: [#4772] Add migration to set select dataType to string 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 --- src/openforms/formio/migration_converters.py | 9 +++++++++ src/openforms/formio/typing/base.py | 1 + .../migrations/0104_select_datatype_string.py | 16 ++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 src/openforms/forms/migrations/0104_select_datatype_string.py diff --git a/src/openforms/formio/migration_converters.py b/src/openforms/formio/migration_converters.py index f4e46b3250..536fa8fcfa 100644 --- a/src/openforms/formio/migration_converters.py +++ b/src/openforms/formio/migration_converters.py @@ -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 + + def convert_simple_conditionals(configuration: JSONObject) -> bool: config_modified = False @@ -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": { diff --git a/src/openforms/formio/typing/base.py b/src/openforms/formio/typing/base.py index c1d0be18f1..c826376408 100644 --- a/src/openforms/formio/typing/base.py +++ b/src/openforms/formio/typing/base.py @@ -89,6 +89,7 @@ class Component(TypedDict): prefill: NotRequired[PrefillConfiguration] openForms: NotRequired[OpenFormsConfig] autocomplete: NotRequired[str] + dataType: NotRequired[str] class FormioConfiguration(TypedDict): diff --git a/src/openforms/forms/migrations/0104_select_datatype_string.py b/src/openforms/forms/migrations/0104_select_datatype_string.py new file mode 100644 index 0000000000..01be2858ba --- /dev/null +++ b/src/openforms/forms/migrations/0104_select_datatype_string.py @@ -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"), + ]