Opened 6 years ago

Closed 17 months 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 6 years ago.
patch_12583.diff (1.6 KB) - added by kwadrat 4 years ago.

Download all attachments as: .zip

Change History (15)

Changed 6 years ago by Ubercore

comment:1 Changed 6 years ago by Ubercore

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

comment:2 Changed 6 years ago by Ubercore

  • Owner changed from nobody to Ubercore
  • Status changed from new to assigned

comment:3 Changed 6 years ago by Ubercore

  • Triage Stage changed from Unreviewed to Ready for checkin

comment:4 Changed 6 years ago by Ubercore

  • Triage Stage changed from Ready for checkin to Accepted

comment:5 Changed 6 years ago by Ubercore

  • milestone set to 1.2

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

comment:6 Changed 5 years ago by ubernostrum

  • milestone 1.2 deleted

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 4 years ago by mattmcc

  • Severity set to Normal
  • Type set to Bug

comment:8 Changed 4 years ago by julien

  • Patch needs improvement set

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

comment:9 Changed 4 years ago by kwadrat

  • Cc kwadrat added
  • Easy pickings unset
  • Resolution set to fixed
  • Status changed from assigned to 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

Changed 4 years ago by kwadrat

comment:10 Changed 4 years ago by kwadrat

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:11 Changed 4 years ago by kwadrat

Waiting for review.

comment:12 Changed 2 years ago by aaugustin

  • Status changed from reopened to new

comment:13 Changed 17 months ago by claudep

  • Resolution set to worksforme
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.
Back to Top