Opened 6 years ago

Last modified 3 years ago

#23572 assigned Bug

Exception on Custom Lookups when right value is None.

Reported by: maherma-adg Owned by: Sergey Fedoseev
Component: Database layer (models, ORM) Version: 1.7
Severity: Normal Keywords: custom lookup, db
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

For my current project I need generate a complex queryset filter and I decide implement as custom lookup.

I got the 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.

Change History (7)

comment:1 Changed 6 years ago by Anssi Kääriäinen

Triage Stage: UnreviewedAccepted

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)).

comment:2 Changed 6 years ago by Brian McDonnell

Owner: changed from nobody to Brian McDonnell
Status: newassigned

comment:3 Changed 6 years ago by Brian McDonnell

Owner: Brian McDonnell deleted
Status: assignednew

comment:4 Changed 6 years ago by Niels Van Och

Owner: set to Niels Van Och
Status: newassigned

comment:5 Changed 6 years ago by Niels Van Och

Owner: Niels Van Och deleted
Status: assignednew

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).

comment:6 Changed 5 years ago by Tim Graham

Description: modified (diff)

comment:7 Changed 3 years ago by Sergey Fedoseev

Owner: set to Sergey Fedoseev
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top