mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #33397 -- Corrected resolving output_field for DateField/DateTimeField/TimeField/DurationFields.
This includes refactoring of CombinedExpression._resolve_output_field() so it no longer uses the behavior inherited from Expression of guessing same output type if argument types match, and instead we explicitly define the output type of all supported operations. This also makes nonsensical operations involving dates (e.g. date + date) raise a FieldError, and adds support for automatically inferring output_field for cases such as: * date - date * date + duration * date - duration * time + duration * time - time
This commit is contained in:
committed by
Mariusz Felisiak
parent
1efea11808
commit
40b8a6174f
@@ -1126,8 +1126,8 @@ class AggregateTestCase(TestCase):
|
||||
|
||||
def test_combine_different_types(self):
|
||||
msg = (
|
||||
"Expression contains mixed types: FloatField, DecimalField. "
|
||||
"You must set output_field."
|
||||
"Cannot infer type of '+' expression involving these types: FloatField, "
|
||||
"DecimalField. You must set output_field."
|
||||
)
|
||||
qs = Book.objects.annotate(sums=Sum("rating") + Sum("pages") + Sum("price"))
|
||||
with self.assertRaisesMessage(FieldError, msg):
|
||||
|
||||
Reference in New Issue
Block a user