Skip to content

Proper handling of null value in JSON request payload #883

Description

@yuanzhou

Low priority enhancement to the null value check/validation with returning 400 error.

Joel encountered a 500 response when he accidentally sent status: None in Python code during the PUT call. Because the Python dict data 'status': None will be converted to JSON "status": null as part of the request payload, then it further triggers AttributeError: 'NoneType' ... when entity-api validates the value...

[2025-06-27 10:54:35] ERROR in app: Exception on /entities/12e5c0024c44eb6ae67a4022a9f61a87 [PUT]
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/usr/src/app/src/./app.py", line 1348, in update_entity
    normalized_status = schema_manager.normalize_status(json_data_dict["status"])
  File "/usr/src/app/src/./schema/schema_manager.py", line 1355, in normalize_status
    if status.lower() == "qa":
AttributeError: 'NoneType' object has no attribute 'lower'

Such exception should be handled properly with returning a 400 error to cover all the possible fields in addition to status.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions