#34091: Invalid SQL: FROM clauses can be omitted when QuerySet is accessed from
multiple threads
-------------------------------------+-------------------------------------
     Reporter:  Marti Raudsepp       |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  4.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  race-condition,      |             Triage Stage:
  orm, threading, SQLCompiler        |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

 > The access from multiple threads was unintentional, but I believe this
 deserves to be fixed in Django anyway

 Thank you for your report and investigation but I disagree with your
 conclusion.

 Django doesn't provide any thread safety guarantees for ORM objects (model
 instances, querysets) and it's your responsibility to ensure that copies
 of these objects are used in threads instead of sharing them. That's the
 reason why thread safe built-in abstractions that interact with the ORM
 and share references to objects (e.g. generic model views) make sure
 
[https://github.com/django/django/blob/da2621c3dfef934000c479750e0276d992025542/django/views/generic/list.py#L32
 they create copies of the references before manipulating them].

 Even if we were to have the compiler make
 
[https://github.com/django/django/blob/da2621c3dfef934000c479750e0276d992025542/django/db/models/sql/compiler.py#L709-L926
 a copy of its query before altering its alias counts] and
 
[https://github.com/django/django/blob/da2621c3dfef934000c479750e0276d992025542/django/db/models/sql/compiler.py#L924-L926
 then setting it back] it's likely only one of the locations that make
 query compilation non-thread safe.

 We can't accept this ticket without committing to making the ORM entirely
 thread-safe with the performance and complexity penalties it incurs. If
 you disagree with my conclusion feel free to open a thread on
 [https://docs.djangoproject.com/en/4.1/internals/mailing-lists/#django-
 developers the developers mailing list] to discuss the subject further.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34091#comment:1>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070183d1d405d1-7afc0461-919c-4d5d-89a6-dcd1f830453f-000000%40eu-central-1.amazonses.com.

Reply via email to