googleapis / googleapis/google-cloud-python

PingingPool.bind() and FixedSizePool.bind() do not pass labels to BatchCreateSessions session_template

Đang mở
#15,872 4 bình luận 0 reaction 1 người được giao Được @rahul2393 nhận Xem trên GitHub
api: spanner
Ngôn ngữ chính
Python
Star
5.4k
Fork
1.8k
Merge trung bình
3 ngày 4 giờ
Pull request đã merge (30 ngày)
122

Mô tả

## Environment

- **OS:** Linux / macOS
- **Python:** 3.10+
- **google-cloud-spanner:** 3.55.0 (also confirmed on `main` branch as of 2026-02-11)

## Summary

`PingingPool.bind()` and `FixedSizePool.bind()` do not include user-assigned `labels` in the `BatchCreateSessionsRequest` `session_template`. This means sessions created eagerly during `bind()` never receive the labels passed to the pool constructor, even though the `labels` parameter is accepted and documented.

## Expected behavior

Sessions created during `PingingPool.bind()` should carry the labels passed via `PingingPool(labels={"key": "value"})`, matching the behavior of `_new_session()` which correctly passes labels.

## Actual behavior

The `session_template` in `bind()` only includes `creator_role`:

```python
# pool.py - PingingPool.bind()
request = BatchCreateSessionsRequest(
database=database.name,
session_count=self.size,
session_template=Session(creator_role=self.database_role), # labels missing
)
```

While `_new_session()` correctly passes labels:

```python
# pool.py - AbstractSessionPool._new_session()
return self._database.session(
labels=self.labels, database_role=self.database_role
)
```

As a result, only sessions lazily created via `_new_session()` (e.g., to replace expired sessions) receive labels. The initial batch of sessions created in `bind()` does not.

## Steps to reproduce

```python
from google.cloud import spanner
from google.cloud.spanner_v1 import SpannerClient

pool = spanner.PingingPool(size=2, default_timeout=10, labels={"env": "test"})
client = spanner.Client(project="my-project")
instance = client.instance("my-instance")
db = instance.database("my-database", pool=pool)

# Check sessions via Admin API
admin_client = SpannerClient()
db_path = f"projects/my-project/instances/my-instance/databases/my-database"
for session in admin_client.list_sessions(database=db_path):
print(dict(session.labels))
# Prints: {} (empty) -- expected: {"env": "test"}

pool.clear()
```

## Suggested fix

Include `self._labels` (or `self.labels`) in the `session_template` passed to `BatchCreateSessionsRequest` in both `PingingPool.bind()` and `FixedSizePool.bind()`:

```python
request = BatchCreateSessionsRequest(
database=database.name,
session_count=self.size,
session_template=Session(
creator_role=self.database_role,
labels=self._labels, # <-- add this
),
)
```

The Spanner API's `BatchCreateSessionsRequest.session_template` already supports `labels` — we confirmed that passing labels in the template correctly applies them to all created sessions.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.