On 03/05/16 14:08, Gavin Wahl wrote:
> > with MyModel.objects.lock():
> > ... do stuff ...
>
> This is misleading as it implies the lock is released when the context
> manager exists, but in postgres at least the lock will be held until the
> end of the transaction.
Hah! Shows how much I know about table locking :P
> What advantage does implementing an ORM API for table locking have over
> `cursor.execute("LOCK TABLE mymodel")`?
Much the same as the rest of the ORM API : Abstraction and convenience.
Even if it's just so you can pass a ModelClass instead of having to know
the table name... and avoid having to access cursor directly.
Perhaps transaction.lock_table(model) since, as you say, it's related to
the term of the transaction?
--
Curtis