I tried to get the records count from ir.attachment using two methods:
1. Executed SQL code with self._cr.execute:
query="""select count(*) from ir_attachment"""
cr=self._cr
cr.execute(query)
val=cr.dictfetchall()
for r in val:
print ("SQL returns....",r)
Code returned 364 rows
2. Using the self.env.search_count:
val=self.env['ir.attachment'].sudo().search_count([])
print ("search_count returns....",val)
In this case the result is 259 rows
Why the difference in the results? Why search_count doesn't return all records?