Opened 4 years ago
Closed 4 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 , 4 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 4 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 4 years ago
comment:4 by , 4 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).
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 ofhas_case_insensitive_likeis set toFalse? @Mariusz Felisiak any suggestion on this?