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

[#4262] Fix invalid default values in radio component #4310

Merged
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
62 changes: 62 additions & 0 deletions bin/report_radio_invalid_default_values.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python
import django

from tabulate import tabulate


def report_null_values() -> bool:
from openforms.forms.models import FormDefinition

problems = []

form_definitions = FormDefinition.objects.iterator()
for fd in form_definitions:
for component in fd.iter_components():
default_value = component["defaultValue"]

if (
component["type"] == "radio"
and isinstance(default_value, str)
and bool(default_value)
):
expected_values = [
radio_value["value"] for radio_value in component["values"]
]

if default_value not in expected_values:
problems.append(
[
fd,
component["label"],
default_value,
]
)

if not problems:
print("No invalid default values found.")
return True

print("Found invalid default values in form definition radio components.")
print("")
print(
tabulate(
problems,
headers=("Form definition", "Component label", "Invalid value"),
)
)

return False


def main(skip_setup=False) -> bool:
from openforms.setup import setup_env

if not skip_setup:
setup_env()
django.setup()

return report_null_values()


if __name__ == "__main__":
main()
Loading