Ray's Knowledge Base

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 = PyObject_IsTrue(v);
Py_DECREF(v);
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 = PyObject_IsTrue(v);
Py_DECREF(v);
if (out < 0) {
    PyErr_Clear();
    return fallback;
}
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.cpp had this pull_bool for the distributed SST workers, and it did not read group_by_file at all, while the coordinator wrote the user's group_by_file into 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 drove False through the old path.