Opened 3 years ago

Closed 3 years ago

#33228 closed Cleanup/optimization (fixed)

Change BaseDatabaseFeatures.has_case_insensitive_like to False

Reported by: Tim Graham Owned by: Chinmoy
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

It seems that a better default for this feature would be False, as of the built-in backends, only SQLite uses True. In addition, all three of the databases I've built third-party backends for (Cloud Spanner, CockroachDB, Snowflake) all use False. Of course, a mention in the release notes that the default is changed is still appropriate.

Change History (6)

comment:1 by Mariusz Felisiak, 3 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Chinmoy, 3 years ago

Owner: changed from nobody to Chinmoy
Status: newassigned

comment:3 by Chinmoy, 3 years ago

I was going through the code and after changing the value to False, one of the tests seemed to fail.

   def test_ticket_16731_startswith_lookup(self):
        Employee.objects.create(firstname="John", lastname="Doe")
        e2 = Employee.objects.create(firstname="Jack", lastname="Jackson")
        e3 = Employee.objects.create(firstname="Jack", lastname="jackson")
        self.assertSequenceEqual(
            Employee.objects.filter(lastname__startswith=F('firstname')),
            [e2, e3] if connection.features.has_case_insensitive_like else [e2]
        )

with the error AssertionError: Sequences differ: <QuerySet [<Employee: Jack Jackson>, <Employee: Jack jackson>]> != [<Employee: Jack Jackson>].
I don't understand why the query filter returns <QuerySet [<Employee: Jack Jackson>, <Employee: Jack jackson>]> when the default value of has_case_insensitive_like is set to False? @Mariusz Felisiak any suggestion on this?

comment:4 by Tim Graham, 3 years ago

You should add has_case_insensitive_like = True to the sqlite3 backend (and remove the now unneeded has_case_insensitive_like = False from the others).

comment:5 by Tim Graham, 3 years ago

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:6 by GitHub <noreply@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In 073b7b59:

Fixed #33228 -- Changed value of BaseDatabaseFeatures.has_case_insensitive_like to False.

Note: See TracTickets for help on using tickets.
Back to Top