There is a web application that is implemented on Flask . The question is this. The idea is this - two different users download for example lists of goods. After that, user A changes the product, and user B also changes the same product. The system must determine that the item has already been changed and the second user overwrites the information entered first. It may look like a message to user B in which it is written that he is overwriting. The system itself works with the application database using SQLAlchemy . Flask itself, by default, processes requests sequentially, so the question of what needs to be done to implement the message sent to user B. I have been searching the Internet for a day, I don’t see anything interesting.

    2 answers 2

    Optimistic locking will save the father of Russian democracy. This is the simplest solution that requires minor modifications:

    1. Add a field to the model that stores the version of the data;
    2. Add exception handling StaleDataError to the handler that saves the item;
    3. Add a template with a form to resolve the conflict.

      Real-time messaging or sending a message to the user about a change can be implemented using SocketIO - https://github.com/miguelgrinberg/python-socketio

      There is an integration with Flask