#21604: Embed raw queries as subqueries when used with an __in filter
-------------------------------------+-------------------------------------
     Reporter:  alex@…               |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

 Andreas, if this is something you'd like to see in Django
 [https://docs.djangoproject.com/en/4.1/internals/contributing/writing-
 code/ you could give a shot submitting a PR] based on the approach
 described in comment:3

 Something along these lines, with regression tests, should get you almost
 all the way there

 {{{#!diff
 diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
 index c2a71ff589..4845ae9e90 100644
 --- a/django/db/models/sql/query.py
 +++ b/django/db/models/sql/query.py
 @@ -82,6 +82,8 @@ def get_children_from_q(q):
  class RawQuery:
      """A single raw SQL query."""

 +    has_select_fields = True
 +
      def __init__(self, sql, using, params=()):
          self.params = params
          self.sql = sql
 @@ -151,6 +153,9 @@ def _execute_query(self):
          self.cursor = connection.cursor()
          self.cursor.execute(self.sql, params)

 +    def as_sql(self, compiler, connection):
 +        return self.sql, self.params
 +

  ExplainInfo = namedtuple("ExplainInfo", ("format", "options"))
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21604#comment:5>
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/010701842e4e5608-b38b9dfd-2d97-4cbd-ba0f-76b98e2314ab-000000%40eu-central-1.amazonses.com.

Reply via email to