Skip to content

Commit

Permalink
fix(models): do not log stream as extra
Browse files Browse the repository at this point in the history
the `stream` dict contains a `msg` key which causes issues with stdlib logging
  • Loading branch information
RobertRosca committed Oct 10, 2023
1 parent eed510f commit 746b123
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/zulip_write_only_proxy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def upload_file(self, file: IO[Any]):
def get_stream_topics(self):
stream = self._client.get_stream_id(self.stream)
if stream["result"] != "success":
log.error(f"failed to get stream id for {self.stream}", extra=stream)
log.error(
f"failed to get stream id for {self.stream}, "
f"zulip api response: {stream}"
)
return stream
stream_id = stream["stream_id"]
return self._client.get_stream_topics(stream_id)
Expand Down
13 changes: 11 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,21 @@ def test_get_stream_topics(scoped_client):


def test_get_stream_topics_log(scoped_client, caplog: pytest.LogCaptureFixture):
scoped_client._client.get_stream_id = MagicMock(return_value={"result": "failure"})
scoped_client._client.get_stream_id = MagicMock(
return_value={
"code": "BAD_REQUEST",
"msg": "Invalid stream name 'nonexistent'",
"result": "error",
}
)

scoped_client.get_stream_topics()

assert len(caplog.records) == 1
assert caplog.records[0].message == "failed to get stream id for Test Stream"
assert caplog.records[0].message == (
"failed to get stream id for Test Stream, zulip api response: "
f"{scoped_client._client.get_stream_id.return_value}"
)


def test_send_message(scoped_client):
Expand Down

0 comments on commit 746b123

Please sign in to comment.