#22489 closed Bug (fixed)
Missing as_sql() implementation for __search lookup
Reported by: | Jakub Roztočil | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | mysql, search, full-text, __search, lookup |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The (MySQL-only) search full-text lookup isn't properly implemented using the new ORM lookup system. It's use results to a runtime exception:
>>> MyModel.objects.filter(field__search='hello world') [...] return node.as_sql(self, self.connection) File "/site-packages/django/db/models/sql/where.py", line 106, in as_sql sql, params = qn.compile(child) File "/site-packages/django/db/models/sql/compiler.py", line 80, in compile return node.as_sql(self, self.connection) File "/site-packages/django/db/models/sql/where.py", line 106, in as_sql sql, params = qn.compile(child) File "/site-packages/django/db/models/sql/compiler.py", line 80, in compile return node.as_sql(self, self.connection) File "/site-packages/django/db/models/lookups.py", line 150, in as_sql rhs_sql = self.get_rhs_op(connection, rhs_sql) File "/site-packages/django/db/models/lookups.py", line 154, in get_rhs_op return connection.operators[self.lookup_name] % rhs KeyError: 'search'
I've opened a pull request here:
Change History (5)
comment:1 by , 11 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Version: | → master |
comment:2 by , 11 years ago
Added a test for MySQL.
It might be a good idea to add a DB feature flag, but the test still needs MySQL-specific CREATE FULLTEXT INDEX […]
however.
(I've accidentally messed up the original pull request and had to open a new one: https://github.com/django/django/pull/2598)
comment:4 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Could you add a regression test for this?
Since it's only supported on MySQL atm you'll need to decorate your tests with
@skipUnless(connection.vendor == 'mysql')
. Since Mark is working on adding support for this to the postgresl backend we might want to add a database feature flag and rely onskipUnlessDbFeature
instead.I guess those tests should live in
tests/lookup/tests.py
.