#24508: F() object operations correcly reflecting with annotate
----------------------------------------------+--------------------
Reporter: mijamo | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.8rc1
Severity: Release blocker | Keywords: F()
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
Hello,
This ticket is related to the 1.8 new feature of using various F
operations within an annotation.
I have spotted 2 problems so far :
1) F('field') * 2 apparently isn't the same as 2 * F('field')
Description of the problem :
{{{
SomeModel.objects.all().annotate(computed = F('some_field') * 2)
Works as expected
SomeModel.objects.all().annotate(computed = 2 * F('some_field'))
E: django.core.exceptions.FieldError: Expression contains mixed types. You
must set output_field
SomeModel.objects.all().annotate(computed = Expression(2 *
F('some_field'), output_field = FloatField()))
E : TypeError: __init__() got multiple values for argument 'output_field'
}}}
The last exception, about init, is the most problematic as it doesn't
state anything about where is the problem (no info in the traceback)
2) When a F object is added to None, it causes a conflict
Description of the problem :
{{{
SomeModel.objects.all().annotate(computed = F('some_field') + None)
Works as expected
SomeModel.objects.all().annotate(computed = None + F('some_field'))
E: django.core.exceptions.FieldError: Expression contains mixed types. You
must set output_field
SomeModel.objects.all().annotate(computed = Expression(None +
F('some_field'), output_field = FloatField()))
E : TypeError: __init__() got multiple values for argument 'output_field'
}}}
You might wonder why there would be a None in the construction. For me it
is because I am building the object in a for, so I have something like
this :
{{{
annotation = None
for field in fields_to_be_added:
annotation += F(field)
SomeModel.objects.all().annotate(annotation)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24508>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.33c13b112b86d7772b47ad10d3ef6e24%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.