Skip to content

Commit

Permalink
🗃️ [#4016] Set up data migration to fix invalid formio configuration
Browse files Browse the repository at this point in the history
The invalid validate keys are dropped from the existing configuration.

This patch also ensures that old form imports are automatically patched
up during import.
  • Loading branch information
sergei-maertens committed Mar 15, 2024
1 parent 7c5fcec commit 757b9fb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
44 changes: 41 additions & 3 deletions src/openforms/formio/migration_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,27 @@ def prevent_datetime_components_from_emptying_invalid_values(
return True


def fix_empty_validate_lengths(component: Component) -> bool:
if not (validate := component.get("validate")):
return False

changed = False
for key in ("minLength", "maxLength", "min", "max", "minWords", "maxWords"):
if key in validate and validate[key] == "": # type: ignore
changed = True
del validate[key] # type: ignore

return changed


CONVERTERS: dict[str, dict[str, ComponentConverter]] = {
# Input components
"textfield": {
"alter_prefill_default_values": alter_prefill_default_values,
"fix_empty_validate_lengths": fix_empty_validate_lengths,
},
"email": {
"fix_empty_validate_lengths": fix_empty_validate_lengths,
},
"date": {
"alter_prefill_default_values": alter_prefill_default_values,
Expand All @@ -164,22 +181,43 @@ def prevent_datetime_components_from_emptying_invalid_values(
"time": {
"move_time_validators": move_time_validators,
},
"select": {"set_openforms_datasrc": set_openforms_datasrc},
"selectboxes": {"set_openforms_datasrc": set_openforms_datasrc},
"radio": {"set_openforms_datasrc": set_openforms_datasrc},
"phoneNumber": {
"fix_empty_validate_lengths": fix_empty_validate_lengths,
},
"postcode": {
"alter_prefill_default_values": alter_prefill_default_values,
"ensure_validate_pattern": ensure_postcode_validate_pattern,
"fix_empty_validate_lengths": fix_empty_validate_lengths,
},
"file": {
"fix_default_value": fix_file_default_value,
},
"textarea": {
"fix_empty_validate_lengths": fix_empty_validate_lengths,
},
"number": {
"fix_empty_validate_lengths": fix_empty_validate_lengths,
},
"select": {"set_openforms_datasrc": set_openforms_datasrc},
"selectboxes": {"set_openforms_datasrc": set_openforms_datasrc},
"currency": {
"fix_empty_validate_lengths": fix_empty_validate_lengths,
},
"radio": {"set_openforms_datasrc": set_openforms_datasrc},
# Special components
"iban": {
"fix_empty_validate_lengths": fix_empty_validate_lengths,
},
"licenseplate": {
"ensure_validate_pattern": ensure_licensplate_validate_pattern,
"fix_empty_validate_lengths": fix_empty_validate_lengths,
},
"bsn": {
"alter_prefill_default_values": alter_prefill_default_values,
"fix_empty_validate_lengths": fix_empty_validate_lengths,
},
"cosign": {
"fix_empty_validate_lengths": fix_empty_validate_lengths,
},
# Layout components
"columns": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

from django.db import migrations

from openforms.forms.migration_operations import ConvertComponentsOperation


class Migration(migrations.Migration):

dependencies = [
("forms", "0095_merge_20240313_1742"),
]

operations = []
operations = [
ConvertComponentsOperation("textfield", "fix_empty_validate_lengths"),
ConvertComponentsOperation("email", "fix_empty_validate_lengths"),
ConvertComponentsOperation("phoneNumber", "fix_empty_validate_lengths"),
ConvertComponentsOperation("postcode", "fix_empty_validate_lengths"),
ConvertComponentsOperation("textarea", "fix_empty_validate_lengths"),
ConvertComponentsOperation("number", "fix_empty_validate_lengths"),
ConvertComponentsOperation("currency", "fix_empty_validate_lengths"),
ConvertComponentsOperation("iban", "fix_empty_validate_lengths"),
ConvertComponentsOperation("licenseplate", "fix_empty_validate_lengths"),
ConvertComponentsOperation("bsn", "fix_empty_validate_lengths"),
ConvertComponentsOperation("cosign", "fix_empty_validate_lengths"),
]

0 comments on commit 757b9fb

Please sign in to comment.