﻿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
12889	Using annotation unexpectedly returns DecimalFields as floats	KyleMac	Greg Wogan-Browne	"Using the following models:


{{{
class Product(models.Model):
    name = models.CharField(_('name'), max_length=64)
    price = models.DecimalField(_('price'), max_digits=5, decimal_places=2)

class Offer(models.Model):
    name = models.CharField(_('name'), max_length=64)
    start_time = models.DateTimeField(_('start time'))
    end_time = models.DateTimeField(_('end time'))
    var1 = models.DecimalField(_('var1'), max_digits=6, decimal_places=2)
    var2 = models.DecimalField(_('var2'), max_digits=6, decimal_places=2,
                               null=True, blank=True)
    contents = models.ManyToManyField(Product,
                                      verbose_name=_('contents'),
                                      related_name='offers')
}}}

Compare the following results:

{{{
now = datetime.utcnow()

# Get all running offers
offers = Offer.objects\
    .filter(start_time__lte=now, end_time__gt=now)
# Will be a Decimal as expected
print type(offers[0].var1)

# Get only running offers that have some contents
offers = Offer.objects\
    .filter(start_time__lte=now, end_time__gt=now)\
    .annotate(num_products=Count('contents'))\
    .exclude(num_products=0)
# Will be a float
print type(offers[0].var1)
}}}"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed	annotate		Accepted	0	0	0	0	0	0
