﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24508	F() object operations do not correcly reflect with annotate	mijamo	Josh Smeaton	"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)
}}}
"	Bug	closed	Database layer (models, ORM)	1.8rc1	Release blocker	fixed	F()		Ready for checkin	1	0	0	0	0	0
