7

I have a Django project which uses a MySQL v5.5 backend with InnoDB storage.
To avoid race condition updates in DB, I'm using select_for_update to lock the rows. Now if this lock stays for a long time, any queries on the locked rows will timeout.
I want to avoid this with one of the following options:

  1. Skip the rows which are locked, similar to SKIP LOCKED option.
  2. Return immediately if some rows you're querying are locked, similar to NOWAIT option.
  3. Reduce the lock wait timeout period for specific queries.

How do I perform any of these with Django ORM?

cezar
  • 11,616
  • 6
  • 48
  • 84
akhil_
  • 233
  • 1
  • 4
  • 10

1 Answers1

3

from Django docs:

You can also ignore locked rows by using select_for_update(skip_locked=True)

Intey
  • 71
  • 6
  • From the documentation `Currently, the postgresql, oracle, and mysql database backends support select_for_update(). However, MySQL doesn’t support the nowait and skip_locked arguments.` and I'm using MySQL. – akhil_ Nov 17 '19 at 09:02
  • Update April 2023, according to Django documentation, MariaDB 10.6+ supports the skip_locked argument, and MySQL 8.0.1+ supports the nowait, skip_locked, and of arguments. – DGideas Apr 11 '23 at 13:41