Code

Opened 4 years ago

Last modified 3 years ago

#14462 assigned Bug

Aggregates default to the database type instead of the field type

Reported by: WoLpH Owned by: wogan
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.

Attachments (0)

Change History (6)

comment:1 Changed 3 years ago by nwp

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to nwp
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 3 years ago by nwp

  • Owner nwp deleted
  • Status changed from assigned to new

comment:3 Changed 3 years ago by wogan

  • Owner set to wogan
  • Status changed from new to assigned

comment:4 Changed 3 years ago by julien

  • Severity set to Normal
  • Type set to Bug

comment:5 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:6 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as assigned
The owner will be changed from wogan to anonymous. Next status will be 'assigned'
The ticket will be disowned. Next status will be 'new'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.