#29145: Allow CIText values to be compared as the database would compare them
(case-insensitively)
--------------------------------------+------------------------------------
     Reporter:  Дилян Палаузов        |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  contrib.postgres      |                  Version:  2.0
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

 * type:  Uncategorized => Cleanup/optimization
 * component:  Uncategorized => contrib.postgres
 * stage:  Unreviewed => Accepted


Old description:

> For comparing two model instances on equality one can iterate over all
> fields in the instance and compare the fields for equality, without
> querying the database.  This does not work for
> django.contrib.postgres.fields.citext.CIText, where "a" is equal to "A".
>
> Under the premise that python and postgresql use the same collation,
> tweak the system to compare two citext-fields in a case-insensitive
> manner for equality, without touching the database (as it is done for all
> other fields).
>
> Attaching to each citext-field returned from the model an {{{__eq__}}}
> doing {{{.lower()}}} could help.

New description:

 For comparing two model instances on equality one can iterate over all
 fields in the instance and compare the fields for equality, without
 querying the database.  This does not work for
 django.contrib.postgres.fields.citext.CIText, where "a" is equal to "A".

 Under the premise that python and postgresql use the same collation, tweak
 the system to compare two citext-fields in a case-insensitive manner for
 equality, without touching the database (as it is done for all other
 fields).

 Attaching to each citext-field returned from the model an `__eq__` doing
 `.lower()` could help.

--

Comment:

 Tentatively accepting, although I'm not certain about the complexity this
 will require. I'm thinking that whenever a value is assigned to a CI
 field, that value will be have to wrapped in a `str` subclass that
 implements `__eq__()` to do the case-insensitive comparison. I guess a
 perfect implementation that considers database collation, for example, may
 not be feasible.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29145#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/072.c07a6706125aa77fd1b1284522a70346%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to