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

Server Error When Option is Not Defined #33

Open
dedenbangkit opened this issue Dec 11, 2023 · 0 comments
Open

Server Error When Option is Not Defined #33

dedenbangkit opened this issue Dec 11, 2023 · 0 comments

Comments

@dedenbangkit
Copy link
Member

dedenbangkit commented Dec 11, 2023

IF we send blank options:

{
  "id": 1699958179804,
  "name": "Toilets uphill from groundwater sources",
  "order": 10,
  "type": "option",
  "tooltip": {
  "text": "INTERVIEW: what percentage of household toilets are located uphill from (above) the nearest groundwater sources?\nToilet uphill of groundwater source: the toilet is located at a higher point than (above) the groundwater source (borehole, dug well or spring)"
  },
  "required": false,
  "meta": false,
  "questionGroupId": 1699951538607,
  "option": [] // empty options
},

or:

{
  "id": 1699958179804,
  "name": "Toilets uphill from groundwater sources",
  "order": 10,
  "type": "option",
  "tooltip": {
  "text": "INTERVIEW: what percentage of household toilets are located uphill from (above) the nearest groundwater sources?\nToilet uphill of groundwater source: the toilet is located at a higher point than (above) the groundwater source (borehole, dug well or spring)"
  },
  "required": false,
  "meta": false,
  "questionGroupId": 1699951538607,
  "option": [{
    "code": null,
    "id": 1702283825467,
    "name": "", // name is blank
    "order": 2
  }]
},

Server will return an internal server error.

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/app/akvo/core_forms/views/form.py", line 95, in put
    serializer.update(
  File "/app/akvo/core_forms/serializers/form.py", line 146, in update
    serializer.update(
  File "/app/akvo/core_forms/serializers/question_group.py", line 111, in update
    serializer.update(
  File "/app/akvo/core_forms/serializers/question.py", line 269, in update
    new_opt_ids = [no.get('id') for no in new_option_data]

Problem: validation in Serializer class

To replicate:

  • Create New Question
  • Choose Option type
  • Leave the Option Blank
  • Save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant