#35972: Custom lookup example raises TypeError
-----------------------------+-----------------------------------------
Reporter: Jacob Walls | Type: Bug
Status: new | Component: Documentation
Version: dev | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+-----------------------------------------
On the forum I [
https://forum.djangoproject.com/t/advanced-postgresql-
functions-like-json-to-recordset-json-jsonb-to-recordset-jsonb/35542/5
shared] the TypeError I was getting when registering a custom lookup for a
`JSONField`:
{{{#!python
File models/lookups.py:13, in NotEqual.as_sql(self, compiler, connection)
11 lhs, lhs_params = self.process_lhs(compiler, connection)
12 rhs, rhs_params = self.process_rhs(compiler, connection)
---> 13 params = lhs_params + rhs_params
14 return "%s <> %s" % (lhs, rhs), params
TypeError: can only concatenate list (not "tuple") to list
}}}
Since this problematic pattern is
[
https://docs.djangoproject.com/en/4.2/howto/custom-lookups/#a-lookup-
example documented], we should either fix the documentation or fix the
underlying reason it doesn't work. I haven't looked into whether there are
backwards-compatible ways to do the latter.
Reproduction is just to follow the documented pattern and register it with
a JSONField e.g. `@JSONField.register_lookup`, and then try to use it in
an ORM query.
--
Ticket URL: <
https://code.djangoproject.com/ticket/35972>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.