API4: Smart group parameters with booleans result in incorrect sql
Overview
API4 smart groups with a boolean parameter result in sql of "where field_name = 'true'" instead of 'where field_name = 1'.
Reproduction steps
- Run this API4 search. Currently this returns about 123 contact IDs.
- Remove the GroupBy and save the search as a smart group
- Open the smart group. It only has 27 people in it.
If you log the sql from CRM_Contact_BAO_GroupContactCache::getApiSQL() you can see the SQL call uses 'true' rather than '1'.
This has unpredictable results! The query doesn't fail - it just returns...something. I've seen it return a subset of the correct results, and sometimes the exact inverse.
Environment information
Tested in latest master (5.38 alpha 1).
Comments
I think this applies to all booleans. The above RelationshipCache was where we hit it, and tests on 'is_deleted' in the more-usual contact entity do the same thing.