#34861: KeyTextTransform incompatible with GeneratedField
-------------------------------------+-------------------------------------
     Reporter:  Paolo Melchiorre     |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  5.0
  (models, ORM)                      |
     Severity:  Release blocker      |               Resolution:
     Keywords:  field, database,     |             Triage Stage:  Accepted
  generated, output_field            |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

 * stage:  Unreviewed => Accepted


Comment:

 The issue lies in `GeneratedField.generated_sql`, it should not call
 `as_sql` directly as it doesn't account for `{vendor}_sql` overrides.

 It should let the compiler compile the expression instead, something like

 {{{#!diff
 diff --git a/django/db/models/fields/generated.py
 b/django/db/models/fields/generated.py
 index deb5875638..225d3e9d12 100644
 --- a/django/db/models/fields/generated.py
 +++ b/django/db/models/fields/generated.py
 @@ -61,12 +61,10 @@ def contribute_to_class(self, *args, **kwargs):
              self.register_lookup(lookup, lookup_name=lookup_name)

      def generated_sql(self, connection):
 -        return self._resolved_expression.as_sql(
 -            compiler=connection.ops.compiler("SQLCompiler")(
 -                self._query, connection=connection, using=None
 -            ),
 -            connection=connection,
 +        compiler = connection.ops.compiler("SQLCompiler")(
 +            self._query, connection=connection, using=None
          )
 +        return compiler.compile(self._resolved_expression)

      def check(self, **kwargs):
          databases = kwargs.get("databases") or [
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34861#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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018ab9fe5c83-d28f4055-e9c8-428f-92d3-70ee9cde88c8-000000%40eu-central-1.amazonses.com.

Reply via email to