-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5123 from open-formulieren/bug/5104-radio-compone…
…nt-default-value-change Components keeping original defaultValue when editing
- Loading branch information
Showing
13 changed files
with
225 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Fix the `defaultValue` of radio components. | ||
# | ||
# Due to a bug in the form editor, when a radio component had a defaultValue of "" | ||
# (empty string) it would automatically be set to `null`. This in turn could cause json | ||
# logic to stop working properly, due to the defaultValue being changed. | ||
# | ||
# This script automatically fixes all defaultValues of radio components that where set | ||
# to `null`. | ||
# Related to ticket: https://github.com/open-formulieren/open-forms/issues/5104 | ||
from __future__ import annotations | ||
|
||
import sys | ||
from pathlib import Path | ||
|
||
import django | ||
|
||
SRC_DIR = Path(__file__).parent.parent / "src" | ||
sys.path.insert(0, str(SRC_DIR.resolve())) | ||
|
||
|
||
def fix_radio_component_default_values(): | ||
from openforms.forms.models import FormDefinition | ||
|
||
form_definitions_to_update = [] | ||
fds = FormDefinition.objects.iterator() | ||
for form_definition in fds: | ||
# Flag to update Form Definition. Is set when child component is changed | ||
should_persist_fd = False | ||
|
||
for component in form_definition.iter_components(): | ||
# The fix is only needed for radio components whose defaultValue is `None` | ||
if component["type"] != "radio" or component["defaultValue"] is not None: | ||
continue | ||
|
||
component["defaultValue"] = "" | ||
# Set flag to update Form Definition | ||
should_persist_fd = True | ||
|
||
if should_persist_fd: | ||
form_definitions_to_update.append(form_definition) | ||
|
||
FormDefinition.objects.bulk_update( | ||
form_definitions_to_update, fields=["configuration"] | ||
) | ||
|
||
|
||
def main(**kwargs): | ||
from openforms.setup import setup_env | ||
|
||
setup_env() | ||
django.setup() | ||
|
||
return fix_radio_component_default_values(**kwargs) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/openforms/forms/migrations/0101_fix_radio_empty_default_value.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Generated by Django 4.2.18 on 2025-03-05 15:25 | ||
|
||
from django.db import migrations | ||
|
||
from openforms.forms.migration_operations import ConvertComponentsOperation | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("forms", "0100_add_interaction_config_to_map_component"), | ||
] | ||
|
||
operations = [ConvertComponentsOperation("radio", "fix_empty_default_value")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters