flask API how to avoid user concurrency in a function

Solution
import threading

DB_LOCK = threading.Lock()

def accept_action(id, user) -> bool:
    if is_valid_id(id):
        with DB_LOCK:
            action = mongo.db.actions.find_one({'_id': ObjectId(id)})
            ...
            mongo.db.actions.update_one({'_id': ObjectId(id)},{'$set': action})

        # Notification for all needed users
        ...
        
LOCKS = {}
def get_lock(name):
    lock = LOCKS.get(name, None)
    if not lock:
        lock = threading.Lock()
        LOCKS[name] = lock
    return lock
with get_lock('user_update'):
    ...