This is a quirk of Field objects. Field inherits from Expression, and the 
__eq__ method of Expression returns a Query object (rather than testing for 
equality and returning a boolean). So, if you do something like myfield == 
some_object, you do not actually get a test of whether myfield is 
equivalent to some_object. Instead, you just get a Query object, which 
apparently evaluates to True in the code Python uses to check for the 
existence of an element in a list. It works this way so you can create DAL 
queries using the db.mytable.myfield == some_value syntax.

If you want to check for a field in a list, consider instead storing the 
field names:

f =
fields = [] in fields

Or using your current code, you can do:

any(field is f for field in fields)

Above, field == f would result in the same problem, but field is f avoids 
the creation of the Query object.


On Friday, September 16, 2016 at 12:41:28 PM UTC-4, Yoel Benitez Fonseca 
> Does this make sense to you? 
> In [1]: fields = list() 
> In [2]: f = 
> In [3]: f in fields 
> Out[3]: False 
> In [4]: fields.append(f) 
> In [5]: f in fields 
> Out[5]: True 
> In [6]: f = db.item.headline 
> In [7]: f in fields 
> Out[7]: True 
> I mean, the last value of 'f' is a fields object but a different one. 
> -- 
> Yoel Benítez Fonseca 
> $ python -c "import this" 

- (Documentation)
- (Source code)
- (Report Issues)
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
For more options, visit

Reply via email to