Opened 14 years ago

Closed 10 years ago

#12583 closed Bug (worksforme)

Postgresql backend uses implicit text casts for case insensitive operators

Reported by: Ubercore Owned by: Ubercore
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: postgresql cast case-insensitive
Cc: kwadrat Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

In django.db.backends.postgresql.operations.DatabaseOperations, a case insensitive lookup produces

UPPER(%s::text)

as the lookup cast sql.

In django.db.backends.postgresql.DatabaseWrapper.operators, a case insensitive lookup produces

UPPER(%s)

Since Postgres 8.3 removed implicit casts, all operators should use ::text. Not doing so breaks lookups that use a type other than text:

AModel.objects.filter(col1__iexact=4)

Attachments (2)

postgres_typecast_fix_and_test.diff (2.6 KB ) - added by Ubercore 14 years ago.
patch_12583.diff (1.6 KB ) - added by kwadrat 12 years ago.

Download all attachments as: .zip

Change History (15)

by Ubercore, 14 years ago

comment:1 by Ubercore, 14 years ago

Has patch: set

comment:2 by Ubercore, 14 years ago

Owner: changed from nobody to Ubercore
Status: newassigned

comment:3 by Ubercore, 14 years ago

Triage Stage: UnreviewedReady for checkin

comment:4 by Ubercore, 14 years ago

Triage Stage: Ready for checkinAccepted

comment:5 by Ubercore, 14 years ago

milestone: 1.2

Changing to 1.2 milestone, as this seems like a low impact bugfix.

comment:6 by James Bennett, 14 years ago

milestone: 1.2

Since iexact doesn't make sense for non-text lookups, I don't think this is critical enough to be on the 1.2 milestone right now.

comment:7 by Matt McClanahan, 13 years ago

Severity: Normal
Type: Bug

comment:8 by Julien Phalip, 13 years ago

Patch needs improvement: set

The tests would need to be rewritten using unittests since this is now Django's preferred way.

comment:9 by kwadrat, 12 years ago

Cc: kwadrat added
Easy pickings: unset
Resolution: fixed
Status: assignedclosed
UI/UX: unset

This ticket can be closed because it is already implemented in: django/db/backends/postgresql_psycopg2/operations.py, class DatabaseOperations, method lookup_cast

by kwadrat, 12 years ago

Attachment: patch_12583.diff added

comment:10 by kwadrat, 12 years ago

Resolution: fixed
Status: closedreopened

comment:11 by kwadrat, 12 years ago

Waiting for review.

comment:12 by Aymeric Augustin, 11 years ago

Status: reopenednew

comment:13 by Claude Paroz, 10 years ago

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top