#24880: Error on all db backends is `select_for_update` is run outside of a
transaction
-------------------------------+--------------------
     Reporter:  suligap        |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Uncategorized  |    Version:  master
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  1
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 A `TransactionManagementError` is now raised when `select_for_update` is
 executed in autocommit mode - but only on backends that support `SELECT
 ... FOR UPDATE`. Perhaps it should be raised also on backends that do not
 support `SELECT ... FOR UPDATE`?

 Reading the documentation:

 > Evaluating a queryset with select_for_update() in autocommit mode is a
 TransactionManagementError error because the rows are not locked in that
 case. If allowed, this would facilitate data corruption and could easily
 be caused by calling code that expects to be run in a transaction outside
 of one.

 > Using select_for_update() on backends which do not support SELECT ...
 FOR UPDATE (such as SQLite) will have no effect.


 It's not 100% clear if the error will be raised on backends that do not
 support `SELECT ... FOR UPDATE`. I was confused by this and assumed that
 it **will** error on `sqlite` - it does not.


 Here's a rough patch that will make `select_for_update` error on all
 backends in that case:
 https://github.com/django/django/compare/master...suligap
 :select_for_update-transaction-error-on-all-backends

 Alternatively, if this does not make sense due to reasons I don't
 understand ATM, maybe we could make the docs be more explicit about this
 aspect.

--
Ticket URL: <https://code.djangoproject.com/ticket/24880>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.e2e52be4c5655d327a0690333f5c2788%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to