airbnb/streamalert

python3 throws TypeError: '<' not supported between instances of 'str' and 'int'

chunyong-lin opened this issue ยท 1 comments

Background

After convert StreamAlert to use python3 after #974, we discover a bug that python3 will throws TypeError: '<' not supported between instances of 'str' and 'int', while python2 will just return False. ๐ŸŒ

The full traceback is

[ERROR] TypeError: '<' not supported between instances of 'str' and 'int'
Traceback (most recent call last):
  File "/var/task/stream_alert/rule_promotion/main.py", line 21, in handler
    RulePromoter().run(event.get('send_digest', False))
  File "/var/task/stream_alert/rule_promotion/promoter.py", line 126, in run
    publisher.publish(list(self._staging_stats.values()))
  File "/var/task/stream_alert/rule_promotion/publisher.py", line 122, in publish
    self._publish_message(stats)
  File "/var/task/stream_alert/rule_promotion/publisher.py", line 104, in _publish_message
    Message=self._format_digest(stats),
  File "/var/task/stream_alert/rule_promotion/publisher.py", line 69, in _format_digest
    return '\n\n'.join(str(stat) for stat in sorted(stats, reverse=True))
  File "/var/task/stream_alert/rule_promotion/statistic.py", line 49, in __lt__
    return self.alert_count < other.alert_count

The root cause is the default value of self.alert_count is unknown, code. Python3 throws TypeError when unknown compares with an integer.

Steps to Reproduce

Did a small verification

  • Use python2
python
Python 2.7.16 (default, Apr 12 2019, 15:32:40)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 'unknown' < 10
False
>>>
  • Use python3
python
Python 3.7.4 (default, Jul  9 2019, 18:13:23)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 'unknown' < 10
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'str' and 'int'
>>>

Desired Change

Change the default value of self.alert_count to -1.

This issue has been resolved. YES!