Skip to content

Commit 2fcce70

Browse files
committed
pool: Handle non-shard-aware endpoints in logging
When connecting to non-shard-aware endpoints, conn.features.shard_id is None. Previously, this would cause a TypeError when logging with %i format specifier. ``` Traceback (most recent call last): File "/usr/lib64/python3.12/logging/__init__.py", line 1160, in emit msg = self.format(record) ^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.12/logging/__init__.py", line 999, in format return fmt.format(record) ^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/site-packages/_pytest/logging.py", line 136, in format return super().format(record) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.12/logging/__init__.py", line 703, in format record.message = record.getMessage() ^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.12/logging/__init__.py", line 392, in getMessage msg = msg % self.args ~~~~^~~~~~~~~~~ TypeError: %i format: a real number is required, not NoneType Call stack: File "/usr/lib64/python3.12/threading.py", line 1032, in _bootstrap self._bootstrap_inner() File "/usr/lib64/python3.12/threading.py", line 1075, in _bootstrap_inner self.run() File "/usr/lib64/python3.12/threading.py", line 1012, in run self._target(*self._args, **self._kwargs) File "/usr/lib64/python3.12/concurrent/futures/thread.py", line 92, in _worker work_item.run() File "/usr/lib64/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) Message: 'Received a connection %s for shard_id=%i on host %s' Arguments: (140333813254336, None, <Host: 127.67.173.34:9042 dc2>) ``` Now prints -1 as a fallback value instead of raising an exception. This fixes logging failures that occurred when: - Connecting to non-shard-aware endpoints - Debug logging level was enabled Signed-off-by: Kefu Chai <[email protected]>
1 parent 1316cd1 commit 2fcce70

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cassandra/pool.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,11 @@ def _open_connection_to_missing_shard(self, shard_id):
731731
else:
732732
conn = self._session.cluster.connection_factory(self.host.endpoint, host_conn=self, on_orphaned_stream_released=self.on_orphaned_stream_released)
733733

734-
log.debug("Received a connection %s for shard_id=%i on host %s", id(conn), conn.features.shard_id, self.host)
734+
log.debug(
735+
"Received a connection %s for shard_id=%i on host %s",
736+
id(conn),
737+
conn.features.shard_id if conn.features.shard_id is not None else -1,
738+
self.host)
735739
if self.is_shutdown:
736740
log.debug("Pool for host %s is in shutdown, closing the new connection (%s)", self.host, id(conn))
737741
conn.close()

0 commit comments

Comments
 (0)