Thanks to visit codestin.com
Credit goes to github.com

Skip to content
22 changes: 9 additions & 13 deletions google/cloud/bigtable_v2/services/bigtable/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def read_rows(
if regex_match and regex_match.group("table_name"):
header_params["table_name"] = regex_match.group("table_name")

if request.app_profile_id:
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

routing_param_regex = re.compile(
Expand Down Expand Up @@ -510,7 +510,7 @@ def sample_row_keys(
if regex_match and regex_match.group("table_name"):
header_params["table_name"] = regex_match.group("table_name")

if request.app_profile_id:
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

routing_param_regex = re.compile(
Expand Down Expand Up @@ -655,7 +655,7 @@ async def mutate_row(
if regex_match and regex_match.group("table_name"):
header_params["table_name"] = regex_match.group("table_name")

if request.app_profile_id:
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

routing_param_regex = re.compile(
Expand Down Expand Up @@ -794,7 +794,7 @@ def mutate_rows(
if regex_match and regex_match.group("table_name"):
header_params["table_name"] = regex_match.group("table_name")

if request.app_profile_id:
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

routing_param_regex = re.compile(
Expand Down Expand Up @@ -974,7 +974,7 @@ async def check_and_mutate_row(
if regex_match and regex_match.group("table_name"):
header_params["table_name"] = regex_match.group("table_name")

if request.app_profile_id:
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

routing_param_regex = re.compile(
Expand Down Expand Up @@ -1093,7 +1093,7 @@ async def ping_and_warm(
if regex_match and regex_match.group("name"):
header_params["name"] = regex_match.group("name")

if request.app_profile_id:
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

if header_params:
Expand Down Expand Up @@ -1235,7 +1235,7 @@ async def read_modify_write_row(
if regex_match and regex_match.group("table_name"):
header_params["table_name"] = regex_match.group("table_name")

if request.app_profile_id:
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

routing_param_regex = re.compile(
Expand Down Expand Up @@ -1584,9 +1584,7 @@ async def prepare_query(
if regex_match and regex_match.group("name"):
header_params["name"] = regex_match.group("name")

if request.app_profile_id is not None:
# prepare_query currently requires app_profile_id header to be set
# even when the request param is unpopulated TODO: remove after support is added
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

if header_params:
Expand Down Expand Up @@ -1706,9 +1704,7 @@ def execute_query(
if regex_match and regex_match.group("name"):
header_params["name"] = regex_match.group("name")

if request.app_profile_id is not None:
# execute_query currently requires app_profile_id header to be set
# even when the request param is unpopulated TODO: remove after support is added
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

if header_params:
Expand Down
22 changes: 9 additions & 13 deletions google/cloud/bigtable_v2/services/bigtable/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def read_rows(
if regex_match and regex_match.group("table_name"):
header_params["table_name"] = regex_match.group("table_name")

if request.app_profile_id:
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

routing_param_regex = re.compile(
Expand Down Expand Up @@ -983,7 +983,7 @@ def sample_row_keys(
if regex_match and regex_match.group("table_name"):
header_params["table_name"] = regex_match.group("table_name")

if request.app_profile_id:
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

routing_param_regex = re.compile(
Expand Down Expand Up @@ -1125,7 +1125,7 @@ def mutate_row(
if regex_match and regex_match.group("table_name"):
header_params["table_name"] = regex_match.group("table_name")

if request.app_profile_id:
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

routing_param_regex = re.compile(
Expand Down Expand Up @@ -1261,7 +1261,7 @@ def mutate_rows(
if regex_match and regex_match.group("table_name"):
header_params["table_name"] = regex_match.group("table_name")

if request.app_profile_id:
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

routing_param_regex = re.compile(
Expand Down Expand Up @@ -1438,7 +1438,7 @@ def check_and_mutate_row(
if regex_match and regex_match.group("table_name"):
header_params["table_name"] = regex_match.group("table_name")

if request.app_profile_id:
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

routing_param_regex = re.compile(
Expand Down Expand Up @@ -1554,7 +1554,7 @@ def ping_and_warm(
if regex_match and regex_match.group("name"):
header_params["name"] = regex_match.group("name")

if request.app_profile_id:
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

if header_params:
Expand Down Expand Up @@ -1693,7 +1693,7 @@ def read_modify_write_row(
if regex_match and regex_match.group("table_name"):
header_params["table_name"] = regex_match.group("table_name")

if request.app_profile_id:
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

routing_param_regex = re.compile(
Expand Down Expand Up @@ -2033,9 +2033,7 @@ def prepare_query(
if regex_match and regex_match.group("name"):
header_params["name"] = regex_match.group("name")

if request.app_profile_id is not None:
# prepare_query currently requires app_profile_id header to be set
# even when the request param is unpopulated TODO: remove after support is added
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

if header_params:
Expand Down Expand Up @@ -2152,9 +2150,7 @@ def execute_query(
if regex_match and regex_match.group("name"):
header_params["name"] = regex_match.group("name")

if request.app_profile_id is not None:
# execute_query currently requires app_profile_id header to be set
# even when the request param is unpopulated TODO: remove after support is added
if True: # always attach app_profile_id, even if empty string
header_params["app_profile_id"] = request.app_profile_id

if header_params:
Expand Down
46 changes: 46 additions & 0 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,52 @@ def get_staging_dirs(

s.move(templated_files, excludes=[".coveragerc", "README.rst", ".github/release-please.yml", "noxfile.py"])


# ----------------------------------------------------------------------------
# Always supply app_profile_id in routing headers: https://github.com/googleapis/python-bigtable/pull/1109
# TODO: remove after backend no longer requires empty strings
# ----------------------------------------------------------------------------
for file in ["async_client.py", "client.py"]:
s.replace(
f"google/cloud/bigtable_v2/services/bigtable/{file}",
"if request.app_profile_id:",
"if True: # always attach app_profile_id, even if empty string"
)
# fix tests
s.replace(
"tests/unit/gapic/bigtable_v2/test_bigtable.py",
'expected_headers = {"name": "projects/sample1/instances/sample2"}',
'expected_headers = {"name": "projects/sample1/instances/sample2", "app_profile_id": ""}'
)
s.replace(
"tests/unit/gapic/bigtable_v2/test_bigtable.py",
"""
expected_headers = {
"authorized_view_name": "projects/sample1/instances/sample2/tables/sample3/authorizedViews/sample4"
}
""",
"""
expected_headers = {
"app_profile_id": "",
"authorized_view_name": "projects/sample1/instances/sample2/tables/sample3/authorizedViews/sample4"
}
"""
)
s.replace(
"tests/unit/gapic/bigtable_v2/test_bigtable.py",
"""
expected_headers = {
"table_name": "projects/sample1/instances/sample2/tables/sample3"
}
""",
"""
expected_headers = {
"table_name": "projects/sample1/instances/sample2/tables/sample3",
"app_profile_id": ""
}
"""
)

# ----------------------------------------------------------------------------
# Samples templates
# ----------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions tests/system/data/test_system_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ async def test_ping_and_warm(self, client, table):
assert len(results) == 1
assert results[0] is None

@pytest.mark.skipif(
bool(os.environ.get(BIGTABLE_EMULATOR)),
reason="emulator mode doesn't refresh channel",
)
@CrossSync.pytest
async def test_channel_refresh(self, table_id, instance_id, temp_rows):
"""
Expand Down
4 changes: 4 additions & 0 deletions tests/system/data/test_system_autogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ def test_ping_and_warm(self, client, table):
assert len(results) == 1
assert results[0] is None

@pytest.mark.skipif(
bool(os.environ.get(BIGTABLE_EMULATOR)),
reason="emulator mode doesn't refresh channel",
)
def test_channel_refresh(self, table_id, instance_id, temp_rows):
"""change grpc channel to refresh after 1 second. Schedule a read_rows call after refresh,
to ensure new channel works"""
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/data/_async/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,8 @@ async def test_call_metadata(self, include_app_profile, fn_name, fn_args, gapic_
if include_app_profile:
assert "app_profile_id=profile" in routing_str
else:
assert "app_profile_id=" not in routing_str
# empty app_profile_id should send empty string
assert "app_profile_id=" in routing_str


@CrossSync.convert_class(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/data/_sync_autogen/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ def test_call_metadata(self, include_app_profile, fn_name, fn_args, gapic_fn):
if include_app_profile:
assert "app_profile_id=profile" in routing_str
else:
assert "app_profile_id=" not in routing_str
assert "app_profile_id=" in routing_str


@CrossSync._Sync_Impl.add_mapping_decorator("TestReadRows")
Expand Down
Loading