#35344: GeneratedField get_col output_field bug
-------------------------------------+-------------------------------------
               Reporter:  us77ipis   |          Owner:  us77ipis
                   Type:  Bug        |         Status:  assigned
              Component:  Database   |        Version:  5.0
  layer (models, ORM)                |
               Severity:  Release    |       Keywords:
  blocker                            |
           Triage Stage:             |      Has patch:  1
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Related issue #34838.

 For generated fields, `get_col` gets called with `output_field=<instance
 of the generated field>`. Consequently, if an `alias` is specified, the
 `output_field` of the generated `Col` is of type `GeneratedField` instead
 of the actual `output_field` of the `GeneratedField`, since the current
 code only handles the case where `get_col`'s `output_field` parameter is
 `None`, but not when it is `self`.

 **Error**
 {{{
 File "django/contrib/postgres/fields/ranges.py", line 253, in
 as_postgresql
     cast_internal_type =
 self.lhs.output_field.base_field.get_internal_type()
 AttributeError: 'GeneratedField' object has no attribute 'base_field'
 }}}

 **Patch**

 {{{#!diff
 diff --git a/django/db/models/fields/generated.py
 b/django/db/models/fields/generated.py
 index 257feeeba2..5b6b188df0 100644
 --- a/django/db/models/fields/generated.py
 +++ b/django/db/models/fields/generated.py
 @@ -39,7 +39,7 @@ class GeneratedField(Field):
          return Col(self.model._meta.db_table, self, self.output_field)

      def get_col(self, alias, output_field=None):
 -        if alias != self.model._meta.db_table and output_field is None:
 +        if alias != self.model._meta.db_table and output_field in (None,
 self):
              output_field = self.output_field
          return super().get_col(alias, output_field)
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35344>
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/0107018e9161180e-ac08ff49-747f-474f-80fe-c18271b22a98-000000%40eu-central-1.amazonses.com.

Reply via email to