{"record":{"id":"86949444004012ae","repo":"pallets/flask","slug":"the-view-function-for-request-endpoint-r-did-not","errorCode":null,"errorMessage":"The view function for {request.endpoint!r} did not return a valid response. The function either returned None or ended without a return statement.","messagePattern":"The view function for (.+?) did not return a valid response\\. The function either returned None or ended without a return statement\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/flask/app.py","lineNumber":1310,"sourceCode":"            if len_rv == 3:\n                rv, status, headers = rv  # type: ignore[misc]\n            # decide if a 2-tuple has status or headers\n            elif len_rv == 2:\n                if isinstance(rv[1], (Headers, dict, tuple, list)):\n                    rv, headers = rv  # pyright: ignore\n                else:\n                    rv, status = rv  # type: ignore[assignment,misc]\n            # other sized tuples are not allowed\n            else:\n                raise TypeError(\n                    \"The view function did not return a valid response tuple.\"\n                    \" The tuple must have the form (body, status, headers),\"\n                    \" (body, status), or (body, headers).\"\n                )\n\n        # the body must not be None\n        if rv is None:\n            raise TypeError(\n                f\"The view function for {request.endpoint!r} did not\"\n                \" return a valid response. The function either returned\"\n                \" None or ended without a return statement.\"\n            )\n\n        # make sure the body is an instance of the response class\n        if not isinstance(rv, self.response_class):\n            if isinstance(rv, (str, bytes, bytearray)) or isinstance(rv, cabc.Iterator):\n                # let the response class set the status and headers instead of\n                # waiting to do it manually, so that the class can handle any\n                # special logic\n                rv = self.response_class(\n                    rv,  # pyright: ignore\n                    status=status,\n                    headers=headers,  # type: ignore[arg-type]\n                )\n                status = headers = None\n            elif isinstance(rv, (dict, list)):","sourceCodeStart":1292,"sourceCodeEnd":1328,"githubUrl":"https://github.com/pallets/flask/blob/3596b1ab61cea85edb8970e83ff61daa073facf8/src/flask/app.py#L1292-L1328","documentation":"Raised when a view function's effective body (rv) is None after tuple unpacking. A Flask view must produce a response body; None means the function returned nothing or returned None explicitly, so Flask cannot build a response.","triggerScenarios":"A view with no return statement, a view that returns None, or a view that returns a tuple whose first element is None.","commonSituations":"Forgot a return statement after a refactor; early return with no value (return) in a conditional branch; view that logs and implicitly falls through.","solutions":["Add an explicit return to every branch, e.g. return '' or return jsonify(...).","Return a proper Response or status tuple like ('', 204).","Run a linter/type checker (mypy, pyright) to flag functions missing returns."],"exampleFix":"// before\n@app.route('/x')\ndef x():\n    log_event()  # no return -> raises\n// after\n@app.route('/x')\ndef x():\n    log_event()\n    return '', 204","handlingStrategy":"validation","validationCode":"def require_body(rv):\n    if rv is None:\n        raise TypeError('View must return a non-None body')\n    return rv","typeGuard":"def has_body(rv) -> bool:\n    return rv is not None","tryCatchPattern":"try:\n    return view()\nexcept TypeError as e:\n    if 'did not return a valid response' in str(e):\n        return '', 204\n    raise","preventionTips":["Ensure every branch returns a value.","Use mypy/pyright to flag missing-return paths.","Default to ('', 204) when a view intentionally has no body."],"tags":["view","response","type-error"],"backgroundTag":null,"analyzedSha":"3596b1ab61cea85edb8970e83ff61daa073facf8","analyzedAt":"2026-08-11T20:11:52.622Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}