[CLAIMED] Contributor Invite: Write a Django Middleware to handle "Database is locked" errors

About this Contributor Invite:

  • Task Area: Coding
  • Effort rating: 3/5
  • Skills required: Python, pytest, Django Middlware/Views/Templates

Description of the Problem:

When there are too many simultaneous requests to FreedomBox Service (Plinth), or perhaps when the disk I/O is too slow, users see a Database is locked error. It has been discussed how to handle this and was decided that we will show a simplified error asking for users to retry. But it turns out that this error is misleading and confuses users into believing there is a deeper problem. We want to change what the user sees when there are too many simultaneous requests to FreedomBox Service (Plinth).

What we ask of you:

Handle this error for all requests that user can make. Show a nice message by implementing a Django Middleware. Follow these steps:

  • Create a Django Middleware for handling such common errors in middleware.py and call it CommonErrorMiddleware . In it handle the error django.db.utils.OperationalError and return response with HTTP 503 status code. This is the correct code when server is unavailable due to load.
  • Install this middleware in the list of all middlewares used by FreedomBox. It should rank higher than all other middleware but less than Django provided middlewares.
  • Customize the error message page shown for 503 HTTP status code by creating 503.html template. In it show the error message “System is possibly under heavy load. Please retry later.”. Be sure to internationalize the message. See other error templates as examples.
  • Create a temporary view which just throws the mentioned OperationalError when visited. With this, whenever the temporary view is visited, the error can be seen. Run the application with and without the --develop option on the command line and see the change.
  • Write automated unit test cases for the middleware in test_middleware.py. The tests should cover all branches of the middleware. See tests for other middleware as example.

Link to the issue in GitLab: https://salsa.debian.org/freedombox-team/plinth/issues/1443

How to claim this Contributor Invite :

Do you want to accept this invitation to contribute? If so, follow these steps:

  1. Comment on this forum post indicating that you would like to claim the invite. This will prevent multiple people from working on the same issue at the same time.
  2. Register an account with our GitLab instance and begin making your contributions on the GitLab issue page for this task. You can use the comment section of this forum post to ask questions, but the bulk of the development discussion should happen on GitLab.

Resources:

If you need help with this issue, please feel free to ask for it from members of our core team:

  • Sunil Mohan Adapa (@sunil): Lead Developer & Code Reviewer
  • Joseph Nuthalapati (@njoseph): DevOps Engineer, Developer, & Code Reviewer
  • James Valleroy (@jvalleroy) : Release Manager, Developer, & Code Reviewer

I’d be happy to take a crack at this.

1 Like

@pancrypticon Hi, Brian! Welcome to our community. This contributor invite is now yours!

To introduce myself: My name is Danny, and I work at the FreedomBox Foundation. Since you’re new, I want to make sure that you know about the support we offer our contributors. Check out our “Welcome” page for some basic information and for the contact info of our core team: https://wiki.debian.org/FreedomBox/Welcome

If you have the time, please do join one of our upcoming weekend progress calls and introduce yourself. These calls are completely optional, but you’re always welcome to join!

I’m happy to have you with us!

1 Like

Hi. Do you want the “temporary view” to be included in the MR?

cc: @sunil (our lead developer)

This notification slipped through my queue and I saw this late. The temporary view is just for testing and not needed in the MR.