Changes between Initial Version and Version 1 of Ticket #36117, comment 2


Ignore:
Timestamp:
Jan 19, 2025, 11:49:02 PM (6 hours ago)
Author:
Simon Charette

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #36117, comment 2

    initial v1  
    1 Without implementing the full thing it seems that simply removing the `Case.resolve_expression` implementation (which is basically equivalent to `BaseExpression.resolve_expression`) passes the tests
     1Without implementing the full thing it seems that simply removing the `Case` and `When` specialized `resolve_expression` implementation (which are basically equivalent to `BaseExpression.resolve_expression`) gets the tests passing
    22
    33{{{#!diff
    4 diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py
    5 index 2494ec4139..83ace22086 100644
     4index 2494ec4139..b03d40bdda 100644
    65--- a/django/db/models/expressions.py
    76+++ b/django/db/models/expressions.py
    8 @@ -1686,20 +1686,6 @@ def get_source_expressions(self):
     7@@ -1605,20 +1605,6 @@ def get_source_fields(self):
     8         # We're only interested in the fields of the result expressions.
     9         return [self.result._output_field_or_none]
     10
     11-    def resolve_expression(
     12-        self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False
     13-    ):
     14-        c = self.copy()
     15-        c.is_summary = summarize
     16-        if hasattr(c.condition, "resolve_expression"):
     17-            c.condition = c.condition.resolve_expression(
     18-                query, allow_joins, reuse, summarize, False
     19-            )
     20-        c.result = c.result.resolve_expression(
     21-            query, allow_joins, reuse, summarize, for_save
     22-        )
     23-        return c
     24-
     25     def as_sql(self, compiler, connection, template=None, **extra_context):
     26         connection.ops.check_expression_support(self)
     27         template_params = extra_context
     28@@ -1686,20 +1672,6 @@ def get_source_expressions(self):
    929     def set_source_expressions(self, exprs):
    1030         *self.cases, self.default = exprs
     
    2848         c.cases = c.cases[:]
    2949}}}
     50
     51The only other change I would include is adjusting `BaseExpression.resolve_expression` to avoid calling `source_expression.__bool__` as that could result in the evaluation of `QuerySet` which could cause queries
     52
     53{{{#!diff
     54diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py
     55index 2494ec4139..0bb8332d45 100644
     56--- a/django/db/models/expressions.py
     57+++ b/django/db/models/expressions.py
     58@@ -296,7 +296,7 @@ def resolve_expression(
     59             [
     60                 (
     61                     expr.resolve_expression(query, allow_joins, reuse, summarize)
     62-                    if expr
     63+                    if expr is not None
     64                     else None
     65                 )
     66                 for expr in c.get_source_expressions()
     67}}}
Back to Top