diff --git a/cassandra/connection.py b/cassandra/connection.py index 17fc39a7..a03b1655 100644 --- a/cassandra/connection.py +++ b/cassandra/connection.py @@ -9,7 +9,7 @@ from cassandra.marshal import int8_unpack from cassandra.decoder import (ReadyMessage, AuthenticateMessage, OptionsMessage, StartupMessage, ErrorMessage, CredentialsMessage, QueryMessage, ResultMessage, decode_response, - InvalidRequestException) + InvalidRequestException, SupportedMessage) log = logging.getLogger(__name__) @@ -194,6 +194,11 @@ class Connection(object): def _handle_options_response(self, options_response): if self.is_defunct: return + + if not isinstance(options_response, SupportedMessage): + log.error("Did not get expected SupportedMessage response; instead, got: %s", options_response) + return + log.debug("Received options response on new Connection from %s" % self.host) self.supported_cql_versions = options_response.cql_versions self.remote_supported_compressions = options_response.options['COMPRESSION'] diff --git a/tests/unit/io/test_libevreactor.py b/tests/unit/io/test_libevreactor.py index 7ff9c923..6952e2ef 100644 --- a/tests/unit/io/test_libevreactor.py +++ b/tests/unit/io/test_libevreactor.py @@ -91,10 +91,7 @@ class LibevConnectionTest(unittest.TestCase): # make sure it errored correctly self.assertTrue(c.is_defunct) self.assertTrue(c.connected_event.is_set()) - try: - self.assertTrue(isinstance(c.last_error, ProtocolError)) - except AssertionError: - self.assertTrue(isinstance(c.last_error, AttributeError)) + self.assertTrue(isinstance(c.last_error, ProtocolError)) def test_error_message_on_startup(self, *args): c = self.make_connection()