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 = db.item.id
fields = [f.name]
f.name 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.
Anthony