I got the [https://docs.djangoproject.com/en/1.7/howto/custom-lookups/,
example] as base to create custom lookup, but during test, this expresion:
data = Rsce.filter(duration{{{__}}}ne = None)
throw an exception. Any other expresion run smoothly.
Looking into code exception are thrown in this piece of code:
if value is None:
if lookups[-1] not in ('exact', 'iexact'):
raise ValueError("Cannot use None as a query value")
IMHO the check in lookups must be avoided on custom lookups, allowing them
to manage None values by themselves.
--
Ticket URL: <https://code.djangoproject.com/ticket/23572>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
Yes, it seems this check belongs to the Lookup (with a base implementation
that raises the ValueError).
BTW you are likely going to stumble upon some other limitations in the
current Lookup implementation. A `.exclude(duration__ne=None)` call might
not work as expected (that is, return complement of
`.filter(duration__ne=None)`).
--
Ticket URL: <https://code.djangoproject.com/ticket/23572#comment:1>
* owner: nobody => brianmcdonnell
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/23572#comment:2>
* status: assigned => new
* owner: brianmcdonnell =>
--
Ticket URL: <https://code.djangoproject.com/ticket/23572#comment:3>
* status: new => assigned
* owner: => nielsvanoch
--
Ticket URL: <https://code.djangoproject.com/ticket/23572#comment:4>
* owner: nielsvanoch =>
* status: assigned => new
Comment:
I had a look at this, but couldn't find a good place/pattern to put it in.
The problem is that the behavior of the two lookups that currently act
different (exact and iexact) is tricky to implement, because you need to
have already constructed your Lookup object, but then replace it by a
different one. If anyone has a good idea about a structure to solve this,
I'd be happy to take another crack (although realistically, that person
could probably also complete the patch easily).
--
Ticket URL: <https://code.djangoproject.com/ticket/23572#comment:5>
Old description:
> For my current project I need generate a complex queryset filter and I
> decide implement as custom lookup.
>
> I got the [https://docs.djangoproject.com/en/1.7/howto/custom-lookups/,
> example] as base to create custom lookup, but during test, this
> expresion:
>
> data = Rsce.filter(duration{{{__}}}ne = None)
>
> throw an exception. Any other expresion run smoothly.
>
> Looking into code exception are thrown in this piece of code:
>
> if value is None:
> if lookups[-1] not in ('exact', 'iexact'):
> raise ValueError("Cannot use None as a query value")
>
> IMHO the check in lookups must be avoided on custom lookups, allowing
> them to manage None values by themselves.
New description:
For my current project I need generate a complex queryset filter and I
decide implement as custom lookup.
I got the [https://docs.djangoproject.com/en/1.7/howto/custom-lookups/,
example] as base to create custom lookup, but during test, this
expression:
`data = Rsce.filter(duration__ne = None)`
throws an exception. Any other expression runs smoothly.
Looking into code exception are thrown in this piece of code:
{{{
if value is None:
if lookups[-1] not in ('exact', 'iexact'):
raise ValueError("Cannot use None as a query value")
}}}
IMHO the check in lookups must be avoided on custom lookups, allowing them
to manage None values by themselves.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/23572#comment:6>
* owner: (none) => Sergey Fedoseev
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/23572#comment:7>
* owner: Sergey Fedoseev => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/23572#comment:8>
* status: new => closed
* resolution: => fixed
Comment:
Fixed in c979c0a2b8abca325a549961fd7a17bdc36bcb1f. You can set
`can_use_none_as_rhs = True` to skip this check.
--
Ticket URL: <https://code.djangoproject.com/ticket/23572#comment:9>