-
-
Notifications
You must be signed in to change notification settings - Fork 758
Update rule comparison operators to work with mixed operator types (bytes and strings) #4831
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
Conversation
strings to try to cast both of the operators to string / unicode if the value is of types bytes. This works around the issue under Python 3.x when one of the operators is bytes type and other is string / unicode type which would result in an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
As I understand it's somewhat related to py3 issues highlighted in https://forum.stackstorm.com/t/is-python3-7-officially-supported-by-stackstorm/938
That's correct, this issue only affects Python 3. Tests I've added would already pass under Python 2.x without the changes I added. Having said that, in ideal world, we (and our users) would always be very specific and explicit about the types so we wouldn't need to do this "best effort" type of conversion, but this breaks down in real life for various reasons:
As far as the forum post goes - yes, I believe this could be a fix for that issue, but I haven't seen any logs yet and that was just my best guess when I checked the operators code (and something which immediately stood out to me). It could also be that there are some other issues as well. |
This pull request updates all the rule criteria comparison operators which also work with strings (a lot of operators work on multiple types), to try to convert both operators to unicode / string type if either or both of them are of a type bytes.
In ideal world, user would always know a type of each input, but that's rarely the case. Depending on how data is retrieved or defined (e.g. webhook body, etc.) the actual type might be bytes or a string / unicode.
This means that pretty much the only option we are left with for rule comparison operators to work as expected when mixed types come into play is to try to convert both of the operators to the same common type aka unicode / string.
NOTE: This issue / problem only affects Python 3.x deployments.