#16731: startswith endswith and contains doesn't work with F expression
-------------------------------------+-------------------------------------
Reporter: ronnas@… | Owner: tchaumeny
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: startswith, F(), | Needs documentation: 0
wildcards | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by tchaumeny):
* status: new => assigned
* owner: nobody => tchaumeny
* has_patch: 0 => 1
* version: => master
Comment:
The current implementation (master) looks definitely broken:
* A special case is made of startswith / istartswith which inherit from
PatternLookup whereas contains/icontains/endswith/iendswith don't — see
https://github.com/django/django/blob/master/django/db/models/lookups.py#L263
* Postgres is the only backend defining the corresponding `pattern_ops`
https://github.com/django/django/blob/master/django/db/backends/postgresql_psycopg2/base.py#L88
— used to concatenate the wildcard character when using an `F()`
expression — and this definition does not escape the database content
meaning that % stored in database will be interpreted as wildcard
characters.
In https://github.com/django/django/pull/3284, `PatternLookup` is
inherited for all "LIKE" lookups and the appropriate `pattern_ops` are
provided for Postgresql, MySQL and SQLite — I don't have an Oracle
database to test and there seems to be too much specific code...
--
Ticket URL: <https://code.djangoproject.com/ticket/16731#comment:11>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/074.20593a54447fb666e80e5a64d45fc1c5%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.