growthbook-python icon indicating copy to clipboard operation
growthbook-python copied to clipboard

`_getOrigHashValue` evaluation of an hash attribute that has zero as its value

Open chengdai-qz opened this issue 2 years ago • 0 comments

In the case where a field used in variant assignment has a value of zero, the function _getOrigHashValue will return an empty string and claim that the hashAttribute value is empty, even though that an attribute field with value 0 might have real meaning (i.e. the first user). That is,

self._attributes = {"id": 0}

_getOrigHashValue("id") would output ""

This is because _getOrigHashValue evaluates 0 or "" as false or false since they both are "falsy values", and as a result, it will return the last element of the comparison.

https://github.com/growthbook/growthbook-python/blob/d55de08565851d9807a13e8b40315097d320b811/growthbook.py#L892-L898

While a relative edge case, it might be worth updating _getOrigHashValue to handle a 0 value.

chengdai-qz avatar Dec 07 '23 09:12 chengdai-qz