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

Cannot submit form due to new backend validation #4068

Closed
SilviaAmAm opened this issue Mar 27, 2024 · 1 comment · Fixed by #4070 or #4075
Closed

Cannot submit form due to new backend validation #4068

SilviaAmAm opened this issue Mar 27, 2024 · 1 comment · Fixed by #4070 or #4075
Assignees
Labels
bug Something isn't working needs-backport Fix must be backported to stable release branch owner: utrecht
Milestone

Comments

@SilviaAmAm
Copy link
Contributor

SilviaAmAm commented Mar 27, 2024

Product versie / Product version

2.6.0

Omschrijf het probleem / Describe the bug

Create a form with:

  • An optional text field with multiple = True
  • A date field
  • Something else, but I am not sure what yet

Try to submit: this shows that the call did not validate on the backend. The POST to _complete gives in the invalidParams:

 [
		{
			"name": "steps.0.data.textField.0",
			"code": "null",
			"reason": "Dit veld mag niet leeg zijn."
		},
		{
			"name": "steps.0.data.date",
			"code": "invalid",
			"reason": "Date heeft het verkeerde formaat, gebruik 1 van deze formaten: YYYY-MM-DD."
		},
		{
			"name": "steps",
			"code": "invalid",
			"reason": "None"
		}
]

Stappen om te reproduceren / Steps to reproduce

See form with slug analyse-design-shortcomings on our test env

Another case that has issues, DH form "Beroep op vrijstelling schoolinschrijving"

Validation errors from complete call:

{
    "type": "http://localhost:8000/fouten/ValidationError/",
    "code": "invalid",
    "title": "Invalid input.",
    "status": 400,
    "detail": "",
    "instance": "urn:uuid:3a2e9ce0-0079-4cfe-bbf2-9f90a0e187c0",
    "invalidParams": [
        {
            "name": "steps.0.data.anoniem",
            "code": "required",
            "reason": "Dit veld is vereist."
        },
        {
            "name": "steps.0.data.persoonsgegevens",
            "code": "required",
            "reason": "Dit veld is vereist."
        },
        {
            "name": "steps.0.data.adresgegevens",
            "code": "required",
            "reason": "Dit veld is vereist."
        },
        {
            "name": "steps.0.data.voornaamPrefill",
            "code": "blank",
            "reason": "Dit veld mag niet leeg zijn."
        },
        {
            "name": "steps.0.data.achternaamPrefill",
            "code": "blank",
            "reason": "Dit veld mag niet leeg zijn."
        },
        {
            "name": "steps.0.data.huisnummerPrefill",
            "code": "blank",
            "reason": "Dit veld mag niet leeg zijn."
        },
        {
            "name": "steps.0.data.straatnaamPrefill",
            "code": "blank",
            "reason": "Dit veld mag niet leeg zijn."
        },
        {
            "name": "steps.0.data.plaatsPrefill",
            "code": "blank",
            "reason": "Dit veld mag niet leeg zijn."
        },
        {
            "name": "steps.0.data.contactgegevens",
            "code": "required",
            "reason": "Dit veld is vereist."
        },
        {
            "name": "steps",
            "code": "invalid",
            "reason": "None"
        },
        {
            "name": "steps",
            "code": "invalid",
            "reason": "None"
        },
        {
            "name": "steps",
            "code": "invalid",
            "reason": "None"
        }
    ]
}
@SilviaAmAm SilviaAmAm added bug Something isn't working triage Issue needs to be validated. Remove this label if the issue considered valid. labels Mar 27, 2024
@sergei-maertens sergei-maertens self-assigned this Mar 27, 2024
@sergei-maertens sergei-maertens added needs-backport Fix must be backported to stable release branch and removed triage Issue needs to be validated. Remove this label if the issue considered valid. labels Mar 27, 2024
@sergei-maertens sergei-maertens added this to the Release 2.6.1 milestone Mar 27, 2024
sergei-maertens added a commit that referenced this issue Mar 27, 2024
DRF date fields expect None to be used for empty values, but
Formio datetime (and derived date/time) components send an
empty string for an untouched/empty field.

The date field subclass allows empty string as empty value
too while shortcutting further validation.
sergei-maertens added a commit that referenced this issue Mar 27, 2024
These values are not properly normalized in the formio builder/renderer,
so for now we must adapt our backend.

This applies to all text-based components that support multiple.
sergei-maertens added a commit that referenced this issue Mar 27, 2024
Empty values can be sent both as 'null' or '[]', the latter
seems to be what happens with Formio.
@sergei-maertens
Copy link
Member

sergei-maertens commented Mar 27, 2024

@SilviaAmAm with the linked PR I was able to complete the form after exporting it from our test env

I can't reproduce this error bit:

		{
			"name": "steps",
			"code": "invalid",
			"reason": "None"
		}

edit: just saw it with another form (description updated). I suspect this is present as soon as there are validation errors for a step, need to investigate further!

sergei-maertens added a commit that referenced this issue Mar 27, 2024
Old bugs are still manifesting in new ways, layout
components should not have a validate object, and
definitely not with 'required' set to 'true', but
here we are.

Added a note to #4071 to keep track of this.
sergei-maertens added a commit that referenced this issue Mar 27, 2024
By using None as 'no errors' value, this gets serialized to the
frontend as if there are errors for the 'steps' path. Using an
empty dictionary excludes this from being serialized at all,
because there are no nested errors at all.

This manifests when there are validation errors for one step,
but other steps don't have any validation errors,
incorrectly reporting some sort of error about the steps that
isn't actually there.
sergei-maertens added a commit that referenced this issue Mar 28, 2024
Checked with Silvia whether it can go or not.
sergei-maertens added a commit that referenced this issue Mar 28, 2024
…-form

[#4068] Form with optional fields cannot be submitted
sergei-maertens pushed a commit that referenced this issue Mar 28, 2024
Backend validation was being applied more strict than equivalent in the
frontend, which lead to submissions not being able to be completed.

Fixes the following aspects:

* Treat empty string is empty value for date field
* Don't reject textfield (and derivatives) with multiple=True when
  items inside are null (treat them as empty value/string)
* Allow empty lists for edit grid/repeating group when field is
  not required
* Skip validation for layout components, they never get data
* Ensure that empty string values for optional text fields are
  allowed (also covers derived fields)
* Fixed validation error being returned that doesn't point to
  a particular component

Backport-of: #4070
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-backport Fix must be backported to stable release branch owner: utrecht
Projects
Archived in project
3 participants