Flask: PK Violations Using flask-sqlalchemy
You have two options:
Catch the PK violation and react accordingly, like you already said.
Lock your transaction based on your id: this is more complicated, you need something to synchronize your locks, like redis. Take a look at python-redis-lock. It is just one option, the solution here is to avoid concurrency for a PK.