Skip to content

Commit

Permalink
fix: allow empty headers for btql routing (#1072)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche authored Jan 17, 2025
1 parent 03ebb3f commit e7ecfeb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
3 changes: 2 additions & 1 deletion google/cloud/bigtable_v2/services/bigtable/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,8 @@ def execute_query(
if regex_match and regex_match.group("name"):
header_params["name"] = regex_match.group("name")

if request.app_profile_id:
if request.app_profile_id is not None:
# execute_query currently requires empty header support. TODO: remove after support is added
header_params["app_profile_id"] = request.app_profile_id

if header_params:
Expand Down
3 changes: 2 additions & 1 deletion google/cloud/bigtable_v2/services/bigtable/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,8 @@ def execute_query(
if regex_match and regex_match.group("name"):
header_params["name"] = regex_match.group("name")

if request.app_profile_id:
if request.app_profile_id is not None:
# execute_query currently requires empty header support. TODO: remove after support is adde
header_params["app_profile_id"] = request.app_profile_id

if header_params:
Expand Down
13 changes: 13 additions & 0 deletions tests/system/data/test_system_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,3 +1014,16 @@ async def test_literal_value_filter(
assert len(row_list) == bool(
expect_match
), f"row {type(cell_value)}({cell_value}) not found with {type(filter_input)}({filter_input}) filter"

@CrossSync.pytest
@pytest.mark.usefixtures("client")
@CrossSync.Retry(
predicate=retry.if_exception_type(ClientError), initial=1, maximum=5
)
async def test_execute_query_simple(self, client, table_id, instance_id):
result = await client.execute_query("SELECT 1 AS a, 'foo' AS b", instance_id)
rows = [r async for r in result]
assert len(rows) == 1
row = rows[0]
assert row["a"] == 1
assert row["b"] == "foo"
12 changes: 12 additions & 0 deletions tests/system/data/test_system_autogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,3 +826,15 @@ def test_literal_value_filter(
assert len(row_list) == bool(
expect_match
), f"row {type(cell_value)}({cell_value}) not found with {type(filter_input)}({filter_input}) filter"

@pytest.mark.usefixtures("client")
@CrossSync._Sync_Impl.Retry(
predicate=retry.if_exception_type(ClientError), initial=1, maximum=5
)
def test_execute_query_simple(self, client, table_id, instance_id):
result = client.execute_query("SELECT 1 AS a, 'foo' AS b", instance_id)
rows = [r for r in result]
assert len(rows) == 1
row = rows[0]
assert row["a"] == 1
assert row["b"] == "foo"
18 changes: 15 additions & 3 deletions tests/unit/gapic/bigtable_v2/test_bigtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6868,7 +6868,11 @@ def test_execute_query_routing_parameters_request_1_grpc():

assert args[0] == request_msg

expected_headers = {"name": "projects/sample1/instances/sample2"}
# expect app_profile_id while temporary patch is in place: https://github.com/googleapis/python-bigtable/pull/1072
expected_headers = {
"name": "projects/sample1/instances/sample2",
"app_profile_id": "",
}
assert (
gapic_v1.routing_header.to_grpc_metadata(expected_headers) in kw["metadata"]
)
Expand Down Expand Up @@ -7894,7 +7898,11 @@ async def test_execute_query_routing_parameters_request_1_grpc_asyncio():

assert args[0] == request_msg

expected_headers = {"name": "projects/sample1/instances/sample2"}
# expect app_profile_id while temporary patch is in place: https://github.com/googleapis/python-bigtable/pull/1072
expected_headers = {
"name": "projects/sample1/instances/sample2",
"app_profile_id": "",
}
assert (
gapic_v1.routing_header.to_grpc_metadata(expected_headers) in kw["metadata"]
)
Expand Down Expand Up @@ -9915,7 +9923,11 @@ def test_execute_query_routing_parameters_request_1_rest():

assert args[0] == request_msg

expected_headers = {"name": "projects/sample1/instances/sample2"}
# expect app_profile_id while temporary patch is in place: https://github.com/googleapis/python-bigtable/pull/1072
expected_headers = {
"name": "projects/sample1/instances/sample2",
"app_profile_id": "",
}
assert (
gapic_v1.routing_header.to_grpc_metadata(expected_headers) in kw["metadata"]
)
Expand Down

0 comments on commit e7ecfeb

Please sign in to comment.