Opened 13 years ago

Closed 11 years ago

Last modified 11 years ago

#14879 closed Bug (worksforme)

Aggregates (Min, Max) for CharField fails with Postgresql

Reported by: wejaay Owned by: Greg Wogan-Browne
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: aggregate, postgresql, charfield
Cc: mike@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

If you try to do aggregate on a CharField using with Min or Max, it works fine in sqlite3 but fails in PostgresSQL. I have version 9.0 of postgres and latest dev version of django.

The error occurs because Django is trying to convert the string to float in http://code.djangoproject.com/browser/django/trunk/django/db/backends/__init__.py?rev=9742, line number 399.
Thats the version where this code was first introduced and as far as I can tell its been broken all the way from then to most recent version http://code.djangoproject.com/browser/django/trunk/django/db/backends/__init__.py, line 553.

One fix that seems to work is to change line 549 from elif internal_type in ('DateField', 'DateTimeField', 'TimeField'): to elif internal_type in ('DateField', 'DateTimeField', 'TimeField', 'CharField'):

I dont know if that has other side effects. If I am doing something wrong, please let me know.

Change History (7)

comment:1 by Russell Keith-Magee, 13 years ago

Has patch: set
Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Marking has-patch because there is a proposed fix, but it needs tests, and needs to be turned into a diff.

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

Owner: changed from nobody to Greg Wogan-Browne
Status: newassigned
Version: 1.2SVN

comment:3 by James Addison, 13 years ago

Severity: Normal
Type: Bug

comment:4 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:6 by Mike Fogel, 12 years ago

Cc: mike@… added

comment:7 by Nick Sandford, 11 years ago

Resolution: worksforme
Status: assignedclosed

I can't reproduce this on Django 1.5b2 and PostgreSQL 9.1.7. It appears convert_values was changed in commit 12a96bfa263d514884ef11009913b2f8bb163472 and this would have fixed the issue.

    In [2]: User.objects.all().aggregate(Max('username'))
    Out[2]: {'username__max': u'test'}
Last edited 11 years ago by Nick Sandford (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top