Skip to content

Validation and correction for non-mapping form response #122

Description

@janine9vn

Description

Submitting a non mapping response to a form, such as a list, returns a 500 error. It should return a 4xx error.

Reproduction Steps

  1. Create a form with no required questions
  2. Submit an empty response to that form on the /forms/submit/<form_name> endpoint. See request body below.
  3. The server should return a 500 error, and should generate a traceback on the backend (see below).

Request body:

{
    "response": []
}

Traceback:

File ".\backend\routes\forms\submit.py", line 115, in post
    response["response"][question.id] = None
TypeError: list indices must be integers or slices, not str

Files

No response

Technical Details

We are trying to access fields of the response, without checking if it is a mapping. When passing in a list, a TypeError is generated.

Ideally, the fix will be a validator on the form_response model.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low priority tasks.area: form submissionCode relating to the response submission to forms backend.area: validationCode relating to validation of user input and Pydantic models.triageIssues that require triage attentiontype: bugA bug that needs fixing!

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions