Opened 5 months ago

Closed 5 months ago

#28394 closed Bug (fixed)

BaseExpression.output_field is resolved incorrectly if source expressions have directly set output_field

Reported by: Sergey Fedoseev Owned by: Sergey Fedoseev
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In [1]: from django.db import models
In [2]: from django.db.models.expressions import Func
In [3]: class FuncA(Func):
   ...:         output_field = models.CharField()
   ...:     
In [4]: class FuncB(Func):
   ...:         pass
   ...: 
In [5]: expr = FuncB(FuncA(models.IntegerField()))
In [6]: expr.output_field
---------------------------------------------------------------------------
FieldError                                Traceback (most recent call last)
<ipython-input-6-ac0033dafa8f> in <module>()
----> 1 expr.output_field

/home/sergey/dev/django/django/utils/functional.py in __get__(self, instance, cls)
     34         if instance is None:
     35             return self
---> 36         res = instance.__dict__[self.name] = self.func(instance)
     37         return res
     38 

/home/sergey/dev/django/django/db/models/expressions.py in output_field(self)
    225         """Return the output type of this expressions."""
    226         if self._output_field_or_none is None:
--> 227             raise FieldError("Cannot resolve expression type, unknown output_field")
    228         return self._output_field_or_none
    229 

FieldError: Cannot resolve expression type, unknown output_field

Change History (4)

comment:1 Changed 5 months ago by Sergey Fedoseev

Owner: changed from nobody to Sergey Fedoseev
Status: newassigned

comment:2 Changed 5 months ago by Sergey Fedoseev

Has patch: set

comment:3 Changed 5 months ago by Simon Charette

Triage Stage: UnreviewedAccepted
Version: 1.11master

comment:4 Changed 5 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 504ce391:

Fixed #28394 -- Allowed setting BaseExpression.output_field (renamed from _output_field).

Note: See TracTickets for help on using tickets.
Back to Top