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

Validation and correction for non-mapping form response #122

Open
janine9vn opened this issue Dec 25, 2021 · 0 comments
Open

Validation and correction for non-mapping form response #122

janine9vn opened this issue Dec 25, 2021 · 0 comments
Labels
area: form submission Code relating to the response submission to forms backend. area: validation Code relating to validation of user input and Pydantic models. P3 Low priority tasks. triage Issues that require triage attention type: bug A bug that needs fixing!

Comments

@janine9vn
Copy link
Contributor

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.

@janine9vn janine9vn added area: validation Code relating to validation of user input and Pydantic models. P3 Low priority tasks. area: form submission Code relating to the response submission to forms backend. type: bug A bug that needs fixing! triage Issues that require triage attention labels Dec 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: form submission Code relating to the response submission to forms backend. area: validation Code relating to validation of user input and Pydantic models. P3 Low priority tasks. triage Issues that require triage attention type: bug A bug that needs fixing!
Projects
None yet
Development

No branches or pull requests

1 participant