Opened 4 years ago

Closed 4 years ago

#31755 closed Cleanup/optimization (fixed)

make temporal subtraction work without ExpressionWrapper

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

Description

class Experiment(models.Model):
    start = models.DateTimeField()
    end = models.DateTimeField()

Experiment.objects.annotate(
    delta=F('end') - F('start') + Value(datetime.timedelta(), output_field=DurationField())
)

This gives:

django.core.exceptions.FieldError: Expression contains mixed types: DateTimeField, DurationField. You must set output_field.

Change History (6)

comment:1 by Sergey Fedoseev, 4 years ago

Owner: changed from nobody to Sergey Fedoseev
Status: newassigned

comment:2 by Sergey Fedoseev, 4 years ago

Has patch: set
Last edited 4 years ago by Mariusz Felisiak (previous) (diff)

comment:3 by Carlton Gibson, 4 years ago

Triage Stage: UnreviewedAccepted

Hi Sergey. Thanks — yes, it would be nice it that worked.

comment:4 by Mariusz Felisiak, 4 years ago

Type: UncategorizedCleanup/optimization

comment:5 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 9d519d3:

Fixed #31755 -- Made temporal subtraction resolve output field.

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