Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#24760 closed Bug (wontfix)

Custom Aggregate: Return string (even if aggregate field is other type)

Reported by: Helmut Owned by: nobody
Component: Database layer (models, ORM) Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm writing a custom aggregate that should return a comma-separated string of numbers. In my specific case, the aggregate field is an IntegerField, and so Django tries to cast the aggregate result to int. So then I specified "is_ordinal = False" on the class, but it is still trying to cast to int.

It seems like the code just checks if is_ordinal is True. If it's anything other than true, it casts to the type of the aggregate field. Might this be a bug, or is there another way to get it to not cast to int?

Thanks.

Change History (3)

comment:1 by Tim Graham, 10 years ago

Resolution: wontfix
Status: newclosed

I'm not sure if there's a bug there, however, there is a new expressions API in Django 1.8, and the code you referenced (django.db.models.sql.aggregates) is deprecated, so even if there is a bug there, it won't be fixed.

comment:2 by Josh Smeaton, 10 years ago

To provide a little more information - new aggregates allow you to set the output_field, so you get to decide the python type that comes back (CharField or TextField in your case).

comment:3 by Helmut, 10 years ago

Fantastic! I will use the new API then. Thanks, guys!

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