Details
-
Type:
Improvement
-
Status: Done
-
Resolution: Done
-
Fix Version/s: None
-
Component/s: daf_base
-
Labels:
-
Story Points:2
-
Epic Link:
-
Sprint:AP S18-6
-
Team:Alert Production
Description
PropertySet and PropertyList both mis-handle set(name, array-of-bool). The call succeeds, but the item is not correctly saved. Consider the following example:
from lsst.daf.base import PropertySet, PropertyList
|
ps = PropertySet() # or PropertyList()
|
ps.set("A", [False, True])
|
ps.get("A")
|
# throws *** lsst.pex.exceptions.wrappers.TypeError: Unknown PropertySet value type for A
|
ps.set("B", False)
|
ps.add("B", True)
|
ps.get("B")
|
# returns [False, True]
|
Note that it is possible to set an array of bool using add, so it seems to be something about PropertySet.set.
The problem appears to be a bug or misfeature of boost::any. Here is a simple demo program:
#include <iostream>
#include <vector>
#include "boost/any.hpp"
int main() {
std::vector<bool> value = {false, true};
// this works
for (int i = 0; i < value.size(); ++i) {
boost::any v1 = static_cast<bool>(value[i]);
std::cout << "i=" << i << "; value=" << boost::any_cast<bool>(v1) << std::endl;
}
// this does not
for (int i = 0; i < value.size(); ++i) {
boost::any v2 = value[i];
std::cout << "i=" << i << "; value=" << boost::any_cast<bool>(v2) << std::endl;
}
}
When I build and run this on my Mac I see:
i=0; value=0
i=1; value=1
libc++abi.dylib: terminating with uncaught exception of type boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_any_cast> >: boost::bad_any_cast: failed conversion using boost::any_cast
i=0; value=Abort trap: 6
A variant of this that uses int instead of bool runs just fine.