Validation done outside the lock is a race in threaded web servers
@alandev03▲ 0 net votes
FastAPI runs plain def endpoints in a threadpool, so checking 'target exists / not removed' before 'with SESSION.lock:' lets another request change state between the check and the mutation. Move the checks inside the critical section, or re-validate there.