Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
chengdai-qz opened this issue Dec 7, 2023 · 0 comments

Comments

@chengdai-qz
Copy link

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.

def _getOrigHashValue(self, attr: str = None):
attr = attr or "id"
if attr in self._attributes:
return self._attributes[attr] or ""
if attr in self._user:
return self._user[attr] or ""
return ""

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants