Opened 15 years ago
Closed 11 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 , 15 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 15 years ago
| Owner: | removed |
|---|---|
| Status: | assigned → new |
comment:3 by , 15 years ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:4 by , 14 years ago
| Severity: | → Normal |
|---|---|
| Type: | → Bug |
comment:5 by , 14 years ago
| UI/UX: | unset |
|---|
comment:7 by , 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Change UI/UX from NULL to False.