Opened 7 years ago

Closed 2 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: master
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 7 years ago.
patch_12583.diff (1.6 KB) - added by kwadrat 5 years ago.

Download all attachments as: .zip

Change History (15)

Changed 7 years ago by Ubercore

comment:1 Changed 7 years ago by Ubercore

Has patch: set
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 7 years ago by Ubercore

Owner: changed from nobody to Ubercore
Status: newassigned

comment:3 Changed 7 years ago by Ubercore

Triage Stage: UnreviewedReady for checkin

comment:4 Changed 7 years ago by Ubercore

Triage Stage: Ready for checkinAccepted

comment:5 Changed 7 years ago by Ubercore

milestone: 1.2

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

comment:6 Changed 7 years ago by James Bennett

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 Changed 5 years ago by Matt McClanahan

Severity: Normal
Type: Bug

comment:8 Changed 5 years ago by Julien Phalip

Patch needs improvement: set

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

comment:9 Changed 5 years ago by kwadrat

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

Changed 5 years ago by kwadrat

Attachment: patch_12583.diff added

comment:10 Changed 5 years ago by kwadrat

Resolution: fixed
Status: closedreopened

comment:11 Changed 5 years ago by kwadrat

Waiting for review.

comment:12 Changed 4 years ago by Aymeric Augustin

Status: reopenednew

comment:13 Changed 2 years ago by Claude Paroz

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