I have done some tests:
>>> empty_recordset = self.env['res.users'] # empty recordset
>>> not_empty_recordset = self.env['res.users'].search([('id', '=', 1)]) # recordset with one record
>>> empty_recordset is False
False
>>> empty_recordset is None
False
>>> empty_recordset == False
False
>>> empty_recordset == True
False
>>> bool(empty_recordset)
False
>>> not empty_recordset
True
>>> if empty_recordset: # it is treated as False
... print('hello')
...
>>> bool(not_empty_recordset)
True
>>> if not_empty_recordset:
... print('hello')
...
hello
>>> not not_empty_recordset
False
- When the recordset is cast with
bool()
it returnsTrue
orFalse
. - With
if
andnot
statements the result is the expected as well. - But when it is used with the operators
is
,==
,!=
the result is not the expected.
What is happening? Is the recordset treated as a boolean value only with the if
and not
statements? Are the rest of the operators not overloaded?