Skip to content

Commit 78174b7

Browse files
committed
refactor: Connection now stores a direct reference to its Pool object instead of just the pool ID.
1 parent eefd33a commit 78174b7

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

spannerlib/wrappers/spannerlib-python/spannerlib-python/google/cloud/spannerlib/connection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ def __init__(self, oid: int, pool: "Pool") -> None:
4141
created.
4242
"""
4343
super().__init__(pool.spannerlib, oid)
44-
self._pool_id = pool.oid
44+
self._pool = pool
4545

4646
@property
47-
def pool_id(self) -> int:
48-
"""Returns the pool ID associated with this connection."""
49-
return self._pool_id
47+
def pool(self) -> "Pool":
48+
"""Returns the pool associated with this connection."""
49+
return self._pool
5050

5151
def _close_lib_object(self) -> None:
5252
"""Internal method to close the pool in the Go library."""
5353
try:
5454
logger.info("Closing connection ID: %d", self.oid)
5555
# Call the Go library function to close the connection.
5656
with self.spannerlib.close_connection(
57-
self.pool_id, self.oid
57+
self.pool.oid, self.oid
5858
) as msg:
5959
msg.bind_library(self.spannerlib)
6060
msg.raise_if_error()

spannerlib/wrappers/spannerlib-python/spannerlib-python/tests/unit/test_connection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ def test_initialization(self, mock_pool, mock_spanner_lib):
9292
assert conn.oid == 50
9393

9494
# Verify specific connection attributes
95-
assert conn.pool_id == 999
95+
assert conn.pool.oid == 999
9696

97-
def test_pool_id_property_is_read_only(self, connection):
98-
"""Ensure pool_id cannot be overwritten accidentally."""
99-
assert connection.pool_id == 999
97+
def test_pool_property_is_read_only(self, connection):
98+
"""Ensure pool cannot be overwritten accidentally."""
99+
assert connection.pool.oid == 999
100100

101101
with pytest.raises(AttributeError):
102-
connection.pool_id = 888
102+
connection.pool = None
103103

104104
# -------------------------------------------------------------------------
105105
# Test Methods: Lifecycle & Cleanup

spannerlib/wrappers/spannerlib-python/spannerlib-python/tests/unit/test_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def test_create_connection_success(
208208
mock_lib_instance.create_connection.assert_called_once_with(100)
209209
assert isinstance(conn, Connection)
210210
assert conn.oid == 200
211-
assert conn.pool_id == 100
211+
assert conn.pool.oid == 100
212212
assert conn.spannerlib == mock_lib_instance
213213

214214
def test_create_connection_pool_closed(self, mock_lib_instance):

0 commit comments

Comments
 (0)