Ignacio is correct, the NDB code defines custom magic methods in the Property class to verify comparisons. These functions ( __eq__ , __ne__ , __lt__ , etc.) call this user-defined function _comparison under the hood.
def _comparison(self, op, value): """Internal helper for comparison operators. Args: op: The operator ('=', '<' etc.). Returns: A FilterNode instance representing the requested comparison. """ # NOTE: This is also used by query.gql(). if not self._indexed: raise datastore_errors.BadFilterError( 'Cannot query for unindexed property %s' % self._name) from .query import FilterNode # Import late to avoid circular imports. if value is not None: value = self._do_validate(value) value = self._call_to_base_type(value) value = self._datastore_type(value) return FilterNode(self._name, op, value)
As you can see, the code does not return a logical result, it returns an instance of FilterNode , which itself evaluates the value of truey / falsey for comparison.
Why does the expression Account.userid >= 40 not expand during the call to true or false before passing as an argument?
It technically becomes extended / evaluated before the query() function is called, it just does not calculate a boolean.
Jesse webb
source share