googleapis / googleapis/google-cloud-python

Routing differences between sync and async

Đang mở
#16,387 1 bình luận 0 reaction 1 người được giao Được @daniel-sanche nhận Xem trên GitHub
priority: p3 type: cleanup
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ả

I noticed that sync clients[add a bunch of code to validate routing params, while async clients do not.

[Example Sync:](https://github.com/googleapis/python-bigtable/blob/4105df762f1318c49bba030063897f0c50e4daee/google/cloud/bigtable_v2/services/bigtable/client.py#L543)
```
header_params = {}

routing_param_regex = re.compile(
"^(?Pprojects/[^/]+/instances/[^/]+/tables/[^/]+)$"
)
regex_match = routing_param_regex.match(request.table_name)
if regex_match and regex_match.group("table_name"):
header_params["table_name"] = regex_match.group("table_name")

if request.app_profile_id:
header_params["app_profile_id"] = request.app_profile_id

if header_params:
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata(header_params),
)
```

[Example Async:](https://github.com/googleapis/python-bigtable/blob/4105df762f1318c49bba030063897f0c50e4daee/google/cloud/bigtable_v2/services/bigtable/async_client.py#L292C1-L298C10)
```
# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata(
(("table_name", request.table_name),)
),
)
```

---

The sync client's verification is currently very expensive, since it runs re.compile on each rpc call. It seems like it should be possible to remove the regex lines to match async. But maybe that counts as a breaking change?

If nothing else, the regex lines should be optimized

I can take this on if needed, let me know what you think

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.