10000 Make sure the protocol v5 downgrade for C* <4 if it is not explicitly… · datastax/python-driver@64d4764 · GitHub
[go: up one dir, main page]

Skip to content

Commit 64d4764

Browse files
committed
Make sure the protocol v5 downgrade for C* <4 if it is not explicitly specified
1 parent a3a8cd0 commit 64d4764

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

cassandra/cluster.py

Lines changed: 9 additions & 1 deletion
< 9CA4 td data-grid-cell-id="diff-96bfc85b77a504cf9f31ccf706cecb133eb418bc3e7a125e28bf5fa887d8c6b9-3551-3559-2" data-line-anchor="diff-96bfc85b77a504cf9f31ccf706cecb133eb418bc3e7a125e28bf5fa887d8c6b9R3559" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">

Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
BatchMessage, RESULT_KIND_PREPARED,
6464
RESULT_KIND_SET_KEYSPACE, RESULT_KIND_ROWS,
6565
RESULT_KIND_SCHEMA_CHANGE, ProtocolHandler,
66-
RESULT_KIND_VOID)
66+
RESULT_KIND_VOID, ProtocolException)
6767
from cassandra.metadata import Metadata, protect_name, murmur3, _NodeInfo
6868
from cassandra.policies import (TokenAwarePolicy, DCAwareRoundRobinPolicy, SimpleConvictionPolicy,
6969
ExponentialReconnectionPolicy, HostDistance,
@@ -3548,6 +3548,14 @@ def _try_connect(self, host):
35483548
break
35493549
except ProtocolVersionUnsupported as e:
35503550
self._cluster.protocol_downgrade(host.endpoint, e.startup_version)
3551+
except ProtocolException as e:
3552+
# protocol v5 is out of beta in C* >=4.0-beta5 and is now the default driver
3553+
# protocol version. If the protocol version was not explicitly specified,
3554+
# and that the server raises a beta protocol error, we should downgrade.
3555+
if not self._cluster._protocol_version_explicit and e.is_beta_protocol_error:
3556+
self._cluster.protocol_downgrade(host.endpoint, self._cluster.protocol_version)
3557+
else:
3558+
raise
35513559
35523560
log.debug("[control connection] Established new connection %r, "
35533561
"registering watchers and refreshing schema and topology",

cassandra/protocol.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ class ProtocolException(ErrorMessageSub):
180180
summary = 'Protocol error'
181181
error_code = 0x000A
182182

183+
@property
184+
def is_beta_protocol_error(self):
185+
return 'USE_BETA flag is unset' in str(self)
186+
183187

184188
class BadCredentials(ErrorMessageSub):
185189
summary = 'Bad credentials'

0 commit comments

Comments
 (0)
0