From f4221f2655a66c7920937a673d3872b093e62131 Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Wed, 30 Jan 2019 00:26:53 -0330 Subject: [PATCH] internal_prep_message: Don't call ensure_stream for stream IDs. Ever since we implemented support for stream IDs in Addressee, Addressee.stream_name() can now return None. This commit ensures that _internal_prep_message only calls ensure_stream when Addressee.stream_name() is not None. --- zerver/lib/actions.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 8b581c54ec..34e0c7166d 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -2280,7 +2280,12 @@ def _internal_prep_message(realm: Realm, if realm is None: raise RuntimeError("None is not a valid realm for internal_prep_message!") - if addressee.is_stream(): + # If we have a stream name, and the stream doesn't exist, we + # create it here (though this code path should probably be removed + # eventually, moving that responsibility to the caller). If + # addressee.stream_name() is None (i.e. we're sending to a stream + # by ID), we skip this, as the stream object must already exist. + if addressee.is_stream() and addressee.stream_name() is not None: ensure_stream(realm, addressee.stream_name()) try: