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

self.users.update in slackclient.py crashes on TypeError #187

Open
masq opened this issue Jun 26, 2019 · 1 comment
Open

self.users.update in slackclient.py crashes on TypeError #187

masq opened this issue Jun 26, 2019 · 1 comment
Labels

Comments

@masq
Copy link

masq commented Jun 26, 2019

After running for a while, slackbot will inevitably crash with this error.

Traceback (most recent call last):
  File "./main.py", line 27, in <module>
    main()
  File "./main.py", line 21, in main
    slack.Bot().run()
  File "/home/pi/slackbot/venv/lib/python3.4/site-packages/slackbot/bot.py", line 37, in run
    self._dispatcher.loop()
  File "/home/pi/slackbot/venv/lib/python3.4/site-packages/slackbot/dispatcher.py", line 151, in loop
    self._client.parse_user_data(user)
  File "/home/pi/slackbot/venv/lib/python3.4/site-packages/slackbot/slackclient.py", line 78, in parse_user_data
    self.users.update({u['id']: u for u in user_data})
  File "/home/pi/slackbot/venv/lib/python3.4/site-packages/slackbot/slackclient.py", line 78, in <dictcomp>
    self.users.update({u['id']: u for u in user_data})
TypeError: 'NoneType' object is not subscriptable

Some system information:

$ python --version
Python 3.4.2
$ uname -a
Linux hostname 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux
$ cat /etc/issue
Raspbian GNU/Linux 8 \n \l

It seems to me that when iterating through the user_data list, it is possible to come across a None object in the list, and that trying to access the 'id' key of the (what is presumed, falsely to be a) dict results in a TypeError since the element in user_data is not in fact a dict.

A naïve fix for this would be to change the line to read:

self.users.update({u['id']: u for u in user_data if u is not None})

but I expect that there might be other code that expects user_data to not have a None in it either, and so there needs to be better filtering on elements going into the user_data list in order to enforce that only proper/expected objects make their way in there.

Let me know if you want any more info, etc.

Also, thanks for making this! It's much better than the code that slack themselves put out for working with the RTM API.

@masq
Copy link
Author

masq commented Jun 26, 2019

Suggested label: Bug

@lucywang000 lucywang000 added the bug label Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants