PyObject_IsTrue(v) > 0 ? true : fallback turns False into the default
PitfallVerified 27 Sep 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
A C or C++ helper that reads a boolean attribute from a Python object ignores False when the default is true: the user sets group_by_file=False, and the native code still uses true.
Cause#
The helper was written as:
int out = ;
;
return out > 0 ? true : fallback;
PyObject_IsTrue returns 1 for true, 0 for false and -1 on error. The expression treats 0 (a real False) like an error and returns fallback. With fallback == true, False can never get through.
Fix#
Use the fallback only for the error case, and clear the error:
int out = ;
;
if
return out > 0;
Also keep one converter from the Python object to the native config. When two code paths convert the same object separately, one can read a field the other ignores, and the two sides then disagree about the config.
Evidence#
- dftracer-utils
sst_distribution.cpphad thispull_boolfor the distributed SST workers, and it did not readgroup_by_fileat all, while the coordinator wrote the user'sgroup_by_fileinto the index config. - Stage 10a moved the conversion into one header,
python/py_agg_config.h(agg_config_from_py), used by the workers and the coordinator, with the fixed boolean handling. Found by reading the code; no test droveFalsethrough the old path.