From cb6b40b4495fdb99626d9ffcec577f86e323f68a Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Mon, 11 Nov 2024 13:03:26 +0100 Subject: [PATCH 1/3] :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..327c28a148 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[Literal["string"]] 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"), + ] From 1124d5ca3856778942c0b1f2aaf2a267703e9f67 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Mon, 11 Nov 2024 13:42:54 +0100 Subject: [PATCH 2/3] :white_check_mark: [#4772] Add test for set_datatype_string converter --- .../formio/tests/test_set_datatype_string.py | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/openforms/formio/tests/test_set_datatype_string.py diff --git a/src/openforms/formio/tests/test_set_datatype_string.py b/src/openforms/formio/tests/test_set_datatype_string.py new file mode 100644 index 0000000000..3a6a0fb76f --- /dev/null +++ b/src/openforms/formio/tests/test_set_datatype_string.py @@ -0,0 +1,62 @@ +from django.test import SimpleTestCase, tag + +from openforms.formio.typing import SelectComponent + +from ..migration_converters import set_datatype_string + + +class SetDatatypeStringTests(SimpleTestCase): + @tag("gh-4772") + def test_set_datatype_string(self): + configuration: SelectComponent = { + "type": "select", + "key": "select", + "label": "Select", + "data": { + "values": [ + {"label": "Option 1", "value": "1"}, + {"label": "Option 2", "value": "2"}, + ] + }, + } + + set_datatype_string(configuration) + + assert "dataType" in configuration + self.assertEqual(configuration["dataType"], "string") + + configuration: SelectComponent = { + "type": "select", + "key": "select", + "label": "Select", + "dataType": "integer", + "data": { + "values": [ + {"label": "Option 1", "value": "1"}, + {"label": "Option 2", "value": "2"}, + ] + }, + } + + set_datatype_string(configuration) + + assert "dataType" in configuration + self.assertEqual(configuration["dataType"], "string") + + configuration: SelectComponent = { + "type": "select", + "key": "select", + "label": "Select", + "dataType": "string", + "data": { + "values": [ + {"label": "Option 1", "value": "1"}, + {"label": "Option 2", "value": "2"}, + ] + }, + } + + set_datatype_string(configuration) + + assert "dataType" in configuration + self.assertEqual(configuration["dataType"], "string") From 0fe69b33260deb5929f32a361977d7e5e8ca6f9f Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Tue, 12 Nov 2024 11:48:15 +0100 Subject: [PATCH 3/3] :arrow_up: [#4772] Upgrade formio-builder to 0.32.0 to fix select datatype --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7fd4836bc8..a994304c0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@fortawesome/fontawesome-free": "^6.1.1", "@open-formulieren/design-tokens": "^0.53.0", - "@open-formulieren/formio-builder": "^0.31.0", + "@open-formulieren/formio-builder": "^0.32.0", "@open-formulieren/leaflet-tools": "^1.0.0", "@open-formulieren/monaco-json-editor": "^0.2.0", "@rjsf/core": "^4.2.1", @@ -4429,9 +4429,9 @@ "integrity": "sha512-3Pv32ULCuFOJZ2GaqcpvB45u6xScr0lmW5ETB9P1Ox9TG5nvMcVSwuwYe/GwxbzmvtZgiMQRMKRFT9lNYLeREQ==" }, "node_modules/@open-formulieren/formio-builder": { - "version": "0.31.0", - "resolved": "https://registry.npmjs.org/@open-formulieren/formio-builder/-/formio-builder-0.31.0.tgz", - "integrity": "sha512-gMM3EYU+04fIE0XjiNLTmNfAUl9yNzCcBERwH9hsWVPgduFTYFC0v+kB/SCkg/Zab2bKtv3IugJIksgm1sX36Q==", + "version": "0.32.0", + "resolved": "https://registry.npmjs.org/@open-formulieren/formio-builder/-/formio-builder-0.32.0.tgz", + "integrity": "sha512-XwrAbXeoqQvijS9OfFxk1KyxzzW2xZmaWtBgy+rqAcziaPHk5zaG52YPSHou0T57y3QtKDXp4Lk8q+RBQFqFpA==", "dependencies": { "@ckeditor/ckeditor5-react": "^6.2.0", "@floating-ui/react": "^0.26.4", @@ -23567,9 +23567,9 @@ "integrity": "sha512-3Pv32ULCuFOJZ2GaqcpvB45u6xScr0lmW5ETB9P1Ox9TG5nvMcVSwuwYe/GwxbzmvtZgiMQRMKRFT9lNYLeREQ==" }, "@open-formulieren/formio-builder": { - "version": "0.31.0", - "resolved": "https://registry.npmjs.org/@open-formulieren/formio-builder/-/formio-builder-0.31.0.tgz", - "integrity": "sha512-gMM3EYU+04fIE0XjiNLTmNfAUl9yNzCcBERwH9hsWVPgduFTYFC0v+kB/SCkg/Zab2bKtv3IugJIksgm1sX36Q==", + "version": "0.32.0", + "resolved": "https://registry.npmjs.org/@open-formulieren/formio-builder/-/formio-builder-0.32.0.tgz", + "integrity": "sha512-XwrAbXeoqQvijS9OfFxk1KyxzzW2xZmaWtBgy+rqAcziaPHk5zaG52YPSHou0T57y3QtKDXp4Lk8q+RBQFqFpA==", "requires": { "@ckeditor/ckeditor5-react": "^6.2.0", "@floating-ui/react": "^0.26.4", diff --git a/package.json b/package.json index a1ae7eaa44..36ba0365c9 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "dependencies": { "@fortawesome/fontawesome-free": "^6.1.1", "@open-formulieren/design-tokens": "^0.53.0", - "@open-formulieren/formio-builder": "^0.31.0", + "@open-formulieren/formio-builder": "^0.32.0", "@open-formulieren/leaflet-tools": "^1.0.0", "@open-formulieren/monaco-json-editor": "^0.2.0", "@rjsf/core": "^4.2.1",