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

Response object parsing assumes presence of certain keys #320

Closed
begincalendar opened this issue Jul 2, 2021 · 5 comments
Closed

Response object parsing assumes presence of certain keys #320

begincalendar opened this issue Jul 2, 2021 · 5 comments

Comments

@begincalendar
Copy link

Describe the bug
I'm running HomeAssistant with the Matrix integration and I started seeing the following stack trace pop in my log file:

Error during setup of component matrix

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 248, in _async_setup_component
    result = await task
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/matrix/__init__.py", line 88, in setup
    bot = MatrixBot(
  File "/usr/src/homeassistant/homeassistant/components/matrix/__init__.py", line 169, in __init__
    self._client = self._login()
  File "/usr/src/homeassistant/homeassistant/components/matrix/__init__.py", line 299, in _login
    client = self._login_by_token()
  File "/usr/src/homeassistant/homeassistant/components/matrix/__init__.py", line 328, in _login_by_token
    return MatrixClient(
  File "/usr/local/lib/python3.8/site-packages/matrix_client/client.py", line 152, in __init__
    self._sync()
  File "/usr/local/lib/python3.8/site-packages/matrix_client/client.py", line 558, in _sync
    for presence_update in response['presence']['events']:
KeyError: 'presence'

Having a brief look at the code in this repo, it appears as though there are many cases where keys in the response object are assumed to always be present.
I changed the dictionary lookups with .get() calls and that seemed to fix the issue.

To Reproduce
Unfortunately I don't have a set of steps to reproduce this, it just cropped up.

Expected behavior
More robust parsing of response objects.

@jurgenhaas
Copy link

Confirmed, I'm seeing these both too and using get fixes the problem for now.

@plinss
Copy link

plinss commented Jul 16, 2021

I'm seeing a similar issue with the 'invite' key:

...
File "/var/www/homeassistant/lib/python3.8/site-packages/homeassistant/components/matrix/__init__.py", line 328, in _login_by_token
    return MatrixClient(
  File "/var/www/homeassistant/lib/python3.8/site-packages/matrix_client/client.py", line 152, in __init__
    self._sync()
  File "/var/www/homeassistant/lib/python3.8/site-packages/matrix_client/client.py", line 562, in _sync
    for room_id, invite_room in response['rooms']['invite'].items():
KeyError: 'invite'

@johansmitsnl
Copy link

It is causing since 1.38 version of synapse. There is also a issue reported with HomeAssistant home-assistant/core#53218

Is this a synapse error or a client implementation that needs to be changed?

@johansmitsnl
Copy link

@begincalendar Looks like the fix is merged into master see #321 now it needs a release.

@anoadragon453
Copy link
Member

Thanks for your patience everyone. v0.4.0 of matrix-python-sdk is now up with the fix: https://github.com/matrix-org/matrix-python-sdk/releases/tag/v0.4.0. Please upgrade when you can :)

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

5 participants