Opened 13 years ago

Closed 10 years ago

#14462 closed Bug (fixed)

Aggregates default to the database type instead of the field type

Reported by: Wolph Owned by: Greg Wogan-Browne
Component: Database layer (models, ORM) Version: 1.2
Severity: Normal Keywords: aggregate, annotate, type, coerce
Cc: rick@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

First a little background information, I've got a couple of custom field types which get cast right after loading the model.
So instead of a Decimal I get a Euro object with added features like formatting and stuff like that.

However, it seems that the aggregate/annotate queries in Django do not respect the to_python() method but simply cast to the type specified by the database backend.
This can easily be fixed by modifying convert_values() so it returns this:

return field.to_python(connection.ops.convert_values(value, field))

instead of

return connection.ops.convert_values(value, field)

The convert_values() function: http://code.djangoproject.com/browser/django/trunk/django/db/models/sql/query.py#L298

Would this be the proper location to fix this? Either way, it has to be a bug that the max() of a value returns a different type.

Change History (7)

comment:1 by nwp, 13 years ago

Owner: changed from nobody to nwp
Status: newassigned
Triage Stage: UnreviewedAccepted

comment:2 by nwp, 13 years ago

Owner: nwp removed
Status: assignednew

comment:3 by Greg Wogan-Browne, 13 years ago

Owner: set to Greg Wogan-Browne
Status: newassigned

comment:4 by Julien Phalip, 13 years ago

Severity: Normal
Type: Bug

comment:5 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:6 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:7 by Marc Tamlyn <marc.tamlyn@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In e9103402c0fa873aea58a6a11dba510cd308cb84:

Fixed #18757, #14462, #21565 -- Reworked database-python type conversions

Complete rework of translating data values from database

Deprecation of SubfieldBase, removal of resolve_columns and
convert_values in favour of a more general converter based approach and
public API Field.from_db_value(). Now works seamlessly with aggregation,
.values() and raw queries.

Thanks to akaariai in particular for extensive advice and inspiration,
also to shaib, manfre and timograham for their reviews.

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