Opened 16 years ago
Closed 12 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)
Change History (15)
by , 16 years ago
| Attachment: | postgres_typecast_fix_and_test.diff added | 
|---|
comment:1 by , 16 years ago
| Has patch: | set | 
|---|
comment:2 by , 16 years ago
| Owner: | changed from to | 
|---|---|
| Status: | new → assigned | 
comment:3 by , 16 years ago
| Triage Stage: | Unreviewed → Ready for checkin | 
|---|
comment:4 by , 16 years ago
| Triage Stage: | Ready for checkin → Accepted | 
|---|
comment:5 by , 16 years ago
| milestone: | → 1.2 | 
|---|
comment:6 by , 16 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 , 15 years ago
| Severity: | → Normal | 
|---|---|
| Type: | → Bug | 
comment:8 by , 15 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 , 14 years ago
| Cc: | added | 
|---|---|
| Easy pickings: | unset | 
| Resolution: | → fixed | 
| Status: | assigned → closed | 
| 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 , 14 years ago
| Attachment: | patch_12583.diff added | 
|---|
comment:10 by , 14 years ago
| Resolution: | fixed | 
|---|---|
| Status: | closed → reopened | 
comment:12 by , 13 years ago
| Status: | reopened → new | 
|---|
comment:13 by , 12 years ago
| Resolution: | → worksforme | 
|---|---|
| Status: | new → closed | 
Test committed in [d902fd625d11bd8a69c3a26b5ed90eefa38d2f6d].
Changing to 1.2 milestone, as this seems like a low impact bugfix.