Skip to content

Error raised from Flask app is logged as successful function execution #886

@paulbatum

Description

@paulbatum

If you write a python function using the WSGI support and then raise an error from the flask app, the error is not reported correctly.

Steps to reproduce:

  1. Make a function app that uses flask with the WSGI support
  2. Use something like this:

__init__.py:

import logging

import azure.functions as func
from api.app import application

def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:    
    return func.WsgiMiddleware(application).handle(req, context)    

app.py:

from flask import Flask
from flask_restful import reqparse, Resource, Api

application = Flask(__name__)
api = Api(application)

class Stores(Resource):
    def get(self):     
        raise Exception('server error')

requirements.txt:

aniso8601==9.0.1
click==8.0.1
colorama==0.4.4
Flask==2.0.1
Flask-RESTful==0.3.9
itsdangerous==2.0.1
Jinja2==3.0.1
MarkupSafe==2.0.1
pytz==2021.1
six==1.16.0
Werkzeug==2.0.1
  1. Invoke the function. If running locally, you'll get output like this:

image

Note that in the last line, we say the function succeeded. This is incorrect because the server raised an error. The client gets the response as a 500, so there is no problem with how the response is handled. But any metrics regarding function failures will be thrown out by treating this as a success.

Its possible there are similar issues in this area. I suggest a thorough check of how error cases are handled by the WSGI handler.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions