Bug Fix: AttributeError: 'Flask' object has no attribute 'before_first_request'.

1. Problem

The backend is broken. The backend container stopped and exited.
  • The backend is broken, the frontend is unable to fetch data from the backend.

  • The backend docker container is down.

2. Analysis

  • The backend docker container log shows that something is wrong with the flask decorator.

  • The @app.before_first_request decorator ensures that the init_rollbar() function is executed before the first request to the application.

    • Suitable for one-off initialization tasks in Flask

    Python is misleading here. @app.before_first_request is correct if ever, because it is for one-off task that has to execute prior to any request.

3. Solution

4. Result

  • The Flask server is up and running again (the backend container is running!)

  • The rollbar endpoint /rollbar/test is working.

Last updated