Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [#4772] Add migration to set select dataType to string #4818

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
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


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
62 changes: 62 additions & 0 deletions src/openforms/formio/tests/test_set_datatype_string.py
Original file line number Diff line number Diff line change
@@ -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")
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[Literal["string"]]


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"),
]
Loading