I'm using a get_or_create pattern similar to the answer to this question:
Does SQLAlchemy have an equivalent of Django's get_or_create?
But I'm having trouble with another thread creating an instance (with the same pk) between the 'select' and the 'insert' of the first thread.
Should the get_or_create function lock the table for the two queries? What is the best way of implementing locking with SqlAlchemy?
I'm using postgresql: http://www.postgresql.org/docs/current/static/sql-lock.html
The only sqlalchemy locking functionality I can see is 'for update', which doesn't seem to be the right type of locking?