From 3a9043799b020d911edf01a2055e8b5aa1c3d6e5 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Fri, 30 Jan 2026 13:59:39 -0800 Subject: [PATCH 1/8] chore(samples): update timezone usage --- docs/classic_client/snippets.py | 3 ++- docs/classic_client/snippets_table.py | 17 +++++++++-------- samples/hello/main.py | 3 ++- samples/snippets/writes/write_batch.py | 3 ++- samples/snippets/writes/write_conditionally.py | 3 ++- samples/snippets/writes/write_simple.py | 3 ++- tests/system/v2_client/_helpers.py | 3 ++- tests/system/v2_client/test_data_api.py | 4 +++- tests/unit/v2_client/test_backup.py | 3 ++- tests/unit/v2_client/test_cluster.py | 17 +++++++++-------- tests/unit/v2_client/test_instance.py | 4 ++-- tests/unit/v2_client/test_table.py | 3 ++- 12 files changed, 39 insertions(+), 27 deletions(-) diff --git a/docs/classic_client/snippets.py b/docs/classic_client/snippets.py index fa3aa3627..00609ab4b 100644 --- a/docs/classic_client/snippets.py +++ b/docs/classic_client/snippets.py @@ -42,6 +42,7 @@ from google.cloud._helpers import UTC from google.cloud.bigtable import Client from google.cloud.bigtable import enums +from datetime import timezone UNIQUE_SUFFIX = unique_resource_id("-") @@ -57,7 +58,7 @@ STORAGE_TYPE = enums.StorageType.SSD LABEL_KEY = "python-snippet" LABEL_STAMP = ( - datetime.datetime.utcnow() + datetime.datetime.now(timezone.utc) .replace(microsecond=0, tzinfo=UTC) .strftime("%Y-%m-%dt%H-%M-%S") ) diff --git a/docs/classic_client/snippets_table.py b/docs/classic_client/snippets_table.py index 893135275..32d593d7c 100644 --- a/docs/classic_client/snippets_table.py +++ b/docs/classic_client/snippets_table.py @@ -41,6 +41,7 @@ from google.cloud.bigtable import Client from google.cloud.bigtable import enums from google.cloud.bigtable import column_family +from datetime import timezone INSTANCE_ID = "snippet" + unique_resource_id("-") @@ -54,7 +55,7 @@ STORAGE_TYPE = enums.StorageType.SSD LABEL_KEY = "python-snippet" LABEL_STAMP = ( - datetime.datetime.utcnow() + datetime.datetime.now(timezone.utc) .replace(microsecond=0, tzinfo=UTC) .strftime("%Y-%m-%dt%H-%M-%S") ) @@ -179,7 +180,7 @@ def test_bigtable_write_read_drop_truncate(): value = "value_{}".format(i).encode() row = table.row(row_key) row.set_cell( - COLUMN_FAMILY_ID, col_name, value, timestamp=datetime.datetime.utcnow() + COLUMN_FAMILY_ID, col_name, value, timestamp=datetime.datetime.now(timezone.utc) ) rows.append(row) response = table.mutate_rows(rows) @@ -270,7 +271,7 @@ def test_bigtable_mutations_batcher(): row_key = row_keys[0] row = table.row(row_key) row.set_cell( - COLUMN_FAMILY_ID, column_name, "value-0", timestamp=datetime.datetime.utcnow() + COLUMN_FAMILY_ID, column_name, "value-0", timestamp=datetime.datetime.now(timezone.utc) ) batcher.mutate(row) # Add a collections of rows @@ -279,7 +280,7 @@ def test_bigtable_mutations_batcher(): row = table.row(row_keys[i]) value = "value_{}".format(i).encode() row.set_cell( - COLUMN_FAMILY_ID, column_name, value, timestamp=datetime.datetime.utcnow() + COLUMN_FAMILY_ID, column_name, value, timestamp=datetime.datetime.now(timezone.utc) ) rows.append(row) batcher.mutate_rows(rows) @@ -759,7 +760,7 @@ def test_bigtable_batcher_mutate_flush_mutate_rows(): row_key = b"row_key_1" row = table.row(row_key) row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, "value-0", timestamp=datetime.datetime.utcnow() + COLUMN_FAMILY_ID, COL_NAME1, "value-0", timestamp=datetime.datetime.now(timezone.utc) ) # In batcher, mutate will flush current batch if it @@ -967,12 +968,12 @@ def test_bigtable_row_data_cells_cell_value_cell_values(): value = b"value_in_col1" row = Config.TABLE.row(b"row_key_1") row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.utcnow() + COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.now(timezone.utc) ) row.commit() row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.utcnow() + COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.now(timezone.utc) ) row.commit() @@ -1050,7 +1051,7 @@ def test_bigtable_row_setcell_rowkey(): cell_val = b"cell-val" row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, cell_val, timestamp=datetime.datetime.utcnow() + COLUMN_FAMILY_ID, COL_NAME1, cell_val, timestamp=datetime.datetime.now(timezone.utc) ) # [END bigtable_api_row_set_cell] diff --git a/samples/hello/main.py b/samples/hello/main.py index 7a193ba6f..cb73d7f40 100644 --- a/samples/hello/main.py +++ b/samples/hello/main.py @@ -29,6 +29,7 @@ # [START bigtable_hw_imports] import datetime +from datetime import timezone from google.cloud import bigtable from google.cloud.bigtable import column_family @@ -88,7 +89,7 @@ def main(project_id, instance_id, table_id): row_key = f"greeting{i}".encode() row = table.direct_row(row_key) row.set_cell( - column_family_id, column, value, timestamp=datetime.datetime.utcnow(), + column_family_id, column, value, timestamp=datetime.datetime.now(timezone.utc), ) rows.append(row) table.mutate_rows(rows) diff --git a/samples/snippets/writes/write_batch.py b/samples/snippets/writes/write_batch.py index 8ad4b07a5..e1c6792a1 100644 --- a/samples/snippets/writes/write_batch.py +++ b/samples/snippets/writes/write_batch.py @@ -14,6 +14,7 @@ # limitations under the License. # [START bigtable_writes_batch] import datetime +from datetime import timezone from google.cloud import bigtable from google.cloud.bigtable.batcher import MutationsBatcher @@ -25,7 +26,7 @@ def write_batch(project_id, instance_id, table_id): table = instance.table(table_id) with MutationsBatcher(table=table) as batcher: - timestamp = datetime.datetime.utcnow() + timestamp = datetime.datetime.now(timezone.utc) column_family_id = "stats_summary" rows = [ diff --git a/samples/snippets/writes/write_conditionally.py b/samples/snippets/writes/write_conditionally.py index 7fb640aad..5b4fc5254 100644 --- a/samples/snippets/writes/write_conditionally.py +++ b/samples/snippets/writes/write_conditionally.py @@ -14,6 +14,7 @@ # limitations under the License. # [START bigtable_writes_conditional] import datetime +from datetime import timezone from google.cloud import bigtable from google.cloud.bigtable import row_filters @@ -24,7 +25,7 @@ def write_conditional(project_id, instance_id, table_id): instance = client.instance(instance_id) table = instance.table(table_id) - timestamp = datetime.datetime.utcnow() + timestamp = datetime.datetime.now(timezone.utc) column_family_id = "stats_summary" row_key = "phone#4c410523#20190501" diff --git a/samples/snippets/writes/write_simple.py b/samples/snippets/writes/write_simple.py index 1aa5a810f..fd05a039f 100644 --- a/samples/snippets/writes/write_simple.py +++ b/samples/snippets/writes/write_simple.py @@ -15,6 +15,7 @@ # [START bigtable_writes_simple] import datetime +from datetime import timezone from google.cloud import bigtable @@ -24,7 +25,7 @@ def write_simple(project_id, instance_id, table_id): instance = client.instance(instance_id) table = instance.table(table_id) - timestamp = datetime.datetime.utcnow() + timestamp = datetime.datetime.now(timezone.utc) column_family_id = "stats_summary" row_key = "phone#4c410523#20190501" diff --git a/tests/system/v2_client/_helpers.py b/tests/system/v2_client/_helpers.py index 95261879e..14b55fecd 100644 --- a/tests/system/v2_client/_helpers.py +++ b/tests/system/v2_client/_helpers.py @@ -13,6 +13,7 @@ # limitations under the License. import datetime +from datetime import timezone import grpc from google.api_core import exceptions @@ -41,7 +42,7 @@ def _retry_on_unavailable(exc): def label_stamp(): return ( - datetime.datetime.utcnow() + datetime.datetime.now(timezone.utc) .replace(microsecond=0, tzinfo=UTC) .strftime("%Y-%m-%dt%H-%M-%S") ) diff --git a/tests/system/v2_client/test_data_api.py b/tests/system/v2_client/test_data_api.py index 579837e34..e52921771 100644 --- a/tests/system/v2_client/test_data_api.py +++ b/tests/system/v2_client/test_data_api.py @@ -17,6 +17,8 @@ import pytest +from datetime import timezone + COLUMN_FAMILY_ID1 = "col-fam-id1" COLUMN_FAMILY_ID2 = "col-fam-id2" COL_NAME1 = b"col-name1" @@ -236,7 +238,7 @@ def _write_to_row(row1, row2, row3, row4): from google.cloud._helpers import UTC from google.cloud.bigtable.row_data import Cell - timestamp1 = datetime.datetime.utcnow().replace(tzinfo=UTC) + timestamp1 = datetime.datetime.now(timezone.utc).replace(tzinfo=UTC) timestamp1_micros = _microseconds_from_datetime(timestamp1) # Truncate to millisecond granularity. timestamp1_micros -= timestamp1_micros % 1000 diff --git a/tests/unit/v2_client/test_backup.py b/tests/unit/v2_client/test_backup.py index cc9251a35..b7ecf7b8b 100644 --- a/tests/unit/v2_client/test_backup.py +++ b/tests/unit/v2_client/test_backup.py @@ -20,6 +20,7 @@ from ._testing import _make_credentials from google.cloud._helpers import UTC +from datetime import timezone PROJECT_ID = "project-id" INSTANCE_ID = "instance-id" @@ -38,7 +39,7 @@ def _make_timestamp(): - return datetime.datetime.utcnow().replace(tzinfo=UTC) + return datetime.datetime.now(timezone.utc).replace(tzinfo=UTC) def _make_table_admin_client(): diff --git a/tests/unit/v2_client/test_cluster.py b/tests/unit/v2_client/test_cluster.py index 65ed47437..445f01611 100644 --- a/tests/unit/v2_client/test_cluster.py +++ b/tests/unit/v2_client/test_cluster.py @@ -17,6 +17,7 @@ import pytest from ._testing import _make_credentials +from datetime import timezone PROJECT = "project" INSTANCE_ID = "instance-id" @@ -420,7 +421,7 @@ def test_cluster_create(): from google.cloud.bigtable_admin_v2.types import instance as instance_v2_pb2 from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.utcnow() + NOW = datetime.datetime.now(timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() client = _make_client(project=PROJECT, credentials=credentials, admin=True) @@ -475,7 +476,7 @@ def test_cluster_create_w_cmek(): from google.cloud.bigtable_admin_v2.types import instance as instance_v2_pb2 from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.utcnow() + NOW = datetime.datetime.now(timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() client = _make_client(project=PROJECT, credentials=credentials, admin=True) @@ -535,7 +536,7 @@ def test_cluster_create_w_autoscaling(): from google.cloud.bigtable_admin_v2.types import instance as instance_v2_pb2 from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.utcnow() + NOW = datetime.datetime.now(timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() client = _make_client(project=PROJECT, credentials=credentials, admin=True) @@ -602,7 +603,7 @@ def test_cluster_update(): ) from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.utcnow() + NOW = datetime.datetime.now(timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() @@ -669,7 +670,7 @@ def test_cluster_update_w_autoscaling(): ) from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.utcnow() + NOW = datetime.datetime.now(timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() @@ -728,7 +729,7 @@ def test_cluster_update_w_partial_autoscaling_config(): ) from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.utcnow() + NOW = datetime.datetime.now(timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() @@ -812,7 +813,7 @@ def test_cluster_update_w_both_manual_and_autoscaling(): ) from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.utcnow() + NOW = datetime.datetime.now(timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() @@ -873,7 +874,7 @@ def test_cluster_disable_autoscaling(): from google.cloud.bigtable.instance import Instance from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.utcnow() + NOW = datetime.datetime.now(timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() client = _make_client(project=PROJECT, credentials=credentials, admin=True) diff --git a/tests/unit/v2_client/test_instance.py b/tests/unit/v2_client/test_instance.py index 712fab1f5..c5ef9c9b8 100644 --- a/tests/unit/v2_client/test_instance.py +++ b/tests/unit/v2_client/test_instance.py @@ -277,7 +277,7 @@ def _instance_api_response_for_create(): ) from google.cloud.bigtable_admin_v2.types import instance - NOW = datetime.datetime.utcnow() + NOW = datetime.datetime.now(datetime.timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) metadata = messages_v2_pb2.CreateInstanceMetadata(request_time=NOW_PB) type_url = "type.googleapis.com/{}".format( @@ -503,7 +503,7 @@ def _instance_api_response_for_update(): ) from google.cloud.bigtable_admin_v2.types import instance - NOW = datetime.datetime.utcnow() + NOW = datetime.datetime.now(datetime.timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) metadata = messages_v2_pb2.UpdateInstanceMetadata(request_time=NOW_PB) type_url = "type.googleapis.com/{}".format( diff --git a/tests/unit/v2_client/test_table.py b/tests/unit/v2_client/test_table.py index 1d183e2fb..eab780d63 100644 --- a/tests/unit/v2_client/test_table.py +++ b/tests/unit/v2_client/test_table.py @@ -21,6 +21,7 @@ from google.api_core.exceptions import DeadlineExceeded from ._testing import _make_credentials +from datetime import timezone PROJECT_ID = "project-id" INSTANCE_ID = "instance-id" @@ -1384,7 +1385,7 @@ def test_table_backup_factory_non_defaults(): instance = Instance(INSTANCE_ID, None) table = _make_table(TABLE_ID, instance) - timestamp = datetime.datetime.utcnow().replace(tzinfo=UTC) + timestamp = datetime.datetime.now(timezone.utc).replace(tzinfo=UTC) backup = table.backup( BACKUP_ID, cluster_id=CLUSTER_ID, From f26e41a832b4a52c18b3e8f2b7dcd93d644dbc3c Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Fri, 30 Jan 2026 14:07:12 -0800 Subject: [PATCH 2/8] removed unneeded import --- docs/classic_client/snippets.py | 3 +-- docs/classic_client/snippets_table.py | 17 ++++++++--------- samples/hello/main.py | 3 +-- samples/snippets/writes/write_batch.py | 3 +-- samples/snippets/writes/write_conditionally.py | 3 +-- samples/snippets/writes/write_simple.py | 3 +-- tests/system/v2_client/_helpers.py | 3 +-- tests/system/v2_client/test_data_api.py | 4 +--- tests/unit/v2_client/test_backup.py | 3 +-- tests/unit/v2_client/test_cluster.py | 17 ++++++++--------- tests/unit/v2_client/test_instance.py | 4 ++-- tests/unit/v2_client/test_table.py | 3 +-- 12 files changed, 27 insertions(+), 39 deletions(-) diff --git a/docs/classic_client/snippets.py b/docs/classic_client/snippets.py index 00609ab4b..81cdd3f7b 100644 --- a/docs/classic_client/snippets.py +++ b/docs/classic_client/snippets.py @@ -42,7 +42,6 @@ from google.cloud._helpers import UTC from google.cloud.bigtable import Client from google.cloud.bigtable import enums -from datetime import timezone UNIQUE_SUFFIX = unique_resource_id("-") @@ -58,7 +57,7 @@ STORAGE_TYPE = enums.StorageType.SSD LABEL_KEY = "python-snippet" LABEL_STAMP = ( - datetime.datetime.now(timezone.utc) + datetime.datetime.now(datetime.UTC) .replace(microsecond=0, tzinfo=UTC) .strftime("%Y-%m-%dt%H-%M-%S") ) diff --git a/docs/classic_client/snippets_table.py b/docs/classic_client/snippets_table.py index 32d593d7c..f4c0c4f8f 100644 --- a/docs/classic_client/snippets_table.py +++ b/docs/classic_client/snippets_table.py @@ -41,7 +41,6 @@ from google.cloud.bigtable import Client from google.cloud.bigtable import enums from google.cloud.bigtable import column_family -from datetime import timezone INSTANCE_ID = "snippet" + unique_resource_id("-") @@ -55,7 +54,7 @@ STORAGE_TYPE = enums.StorageType.SSD LABEL_KEY = "python-snippet" LABEL_STAMP = ( - datetime.datetime.now(timezone.utc) + datetime.datetime.now(datetime.UTC) .replace(microsecond=0, tzinfo=UTC) .strftime("%Y-%m-%dt%H-%M-%S") ) @@ -180,7 +179,7 @@ def test_bigtable_write_read_drop_truncate(): value = "value_{}".format(i).encode() row = table.row(row_key) row.set_cell( - COLUMN_FAMILY_ID, col_name, value, timestamp=datetime.datetime.now(timezone.utc) + COLUMN_FAMILY_ID, col_name, value, timestamp=datetime.datetime.now(datetime.UTC) ) rows.append(row) response = table.mutate_rows(rows) @@ -271,7 +270,7 @@ def test_bigtable_mutations_batcher(): row_key = row_keys[0] row = table.row(row_key) row.set_cell( - COLUMN_FAMILY_ID, column_name, "value-0", timestamp=datetime.datetime.now(timezone.utc) + COLUMN_FAMILY_ID, column_name, "value-0", timestamp=datetime.datetime.now(datetime.UTC) ) batcher.mutate(row) # Add a collections of rows @@ -280,7 +279,7 @@ def test_bigtable_mutations_batcher(): row = table.row(row_keys[i]) value = "value_{}".format(i).encode() row.set_cell( - COLUMN_FAMILY_ID, column_name, value, timestamp=datetime.datetime.now(timezone.utc) + COLUMN_FAMILY_ID, column_name, value, timestamp=datetime.datetime.now(datetime.UTC) ) rows.append(row) batcher.mutate_rows(rows) @@ -760,7 +759,7 @@ def test_bigtable_batcher_mutate_flush_mutate_rows(): row_key = b"row_key_1" row = table.row(row_key) row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, "value-0", timestamp=datetime.datetime.now(timezone.utc) + COLUMN_FAMILY_ID, COL_NAME1, "value-0", timestamp=datetime.datetime.now(datetime.UTC) ) # In batcher, mutate will flush current batch if it @@ -968,12 +967,12 @@ def test_bigtable_row_data_cells_cell_value_cell_values(): value = b"value_in_col1" row = Config.TABLE.row(b"row_key_1") row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.now(timezone.utc) + COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.now(datetime.UTC) ) row.commit() row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.now(timezone.utc) + COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.now(datetime.UTC) ) row.commit() @@ -1051,7 +1050,7 @@ def test_bigtable_row_setcell_rowkey(): cell_val = b"cell-val" row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, cell_val, timestamp=datetime.datetime.now(timezone.utc) + COLUMN_FAMILY_ID, COL_NAME1, cell_val, timestamp=datetime.datetime.now(datetime.UTC) ) # [END bigtable_api_row_set_cell] diff --git a/samples/hello/main.py b/samples/hello/main.py index cb73d7f40..aa2dd439c 100644 --- a/samples/hello/main.py +++ b/samples/hello/main.py @@ -29,7 +29,6 @@ # [START bigtable_hw_imports] import datetime -from datetime import timezone from google.cloud import bigtable from google.cloud.bigtable import column_family @@ -89,7 +88,7 @@ def main(project_id, instance_id, table_id): row_key = f"greeting{i}".encode() row = table.direct_row(row_key) row.set_cell( - column_family_id, column, value, timestamp=datetime.datetime.now(timezone.utc), + column_family_id, column, value, timestamp=datetime.datetime.now(datetime.UTC), ) rows.append(row) table.mutate_rows(rows) diff --git a/samples/snippets/writes/write_batch.py b/samples/snippets/writes/write_batch.py index e1c6792a1..2588d01aa 100644 --- a/samples/snippets/writes/write_batch.py +++ b/samples/snippets/writes/write_batch.py @@ -14,7 +14,6 @@ # limitations under the License. # [START bigtable_writes_batch] import datetime -from datetime import timezone from google.cloud import bigtable from google.cloud.bigtable.batcher import MutationsBatcher @@ -26,7 +25,7 @@ def write_batch(project_id, instance_id, table_id): table = instance.table(table_id) with MutationsBatcher(table=table) as batcher: - timestamp = datetime.datetime.now(timezone.utc) + timestamp = datetime.datetime.now(datetime.UTC) column_family_id = "stats_summary" rows = [ diff --git a/samples/snippets/writes/write_conditionally.py b/samples/snippets/writes/write_conditionally.py index 5b4fc5254..03a0acdfc 100644 --- a/samples/snippets/writes/write_conditionally.py +++ b/samples/snippets/writes/write_conditionally.py @@ -14,7 +14,6 @@ # limitations under the License. # [START bigtable_writes_conditional] import datetime -from datetime import timezone from google.cloud import bigtable from google.cloud.bigtable import row_filters @@ -25,7 +24,7 @@ def write_conditional(project_id, instance_id, table_id): instance = client.instance(instance_id) table = instance.table(table_id) - timestamp = datetime.datetime.now(timezone.utc) + timestamp = datetime.datetime.now(datetime.UTC) column_family_id = "stats_summary" row_key = "phone#4c410523#20190501" diff --git a/samples/snippets/writes/write_simple.py b/samples/snippets/writes/write_simple.py index fd05a039f..a7f67731c 100644 --- a/samples/snippets/writes/write_simple.py +++ b/samples/snippets/writes/write_simple.py @@ -15,7 +15,6 @@ # [START bigtable_writes_simple] import datetime -from datetime import timezone from google.cloud import bigtable @@ -25,7 +24,7 @@ def write_simple(project_id, instance_id, table_id): instance = client.instance(instance_id) table = instance.table(table_id) - timestamp = datetime.datetime.now(timezone.utc) + timestamp = datetime.datetime.now(datetime.UTC) column_family_id = "stats_summary" row_key = "phone#4c410523#20190501" diff --git a/tests/system/v2_client/_helpers.py b/tests/system/v2_client/_helpers.py index 14b55fecd..8b7e5ff06 100644 --- a/tests/system/v2_client/_helpers.py +++ b/tests/system/v2_client/_helpers.py @@ -13,7 +13,6 @@ # limitations under the License. import datetime -from datetime import timezone import grpc from google.api_core import exceptions @@ -42,7 +41,7 @@ def _retry_on_unavailable(exc): def label_stamp(): return ( - datetime.datetime.now(timezone.utc) + datetime.datetime.now(datetime.UTC) .replace(microsecond=0, tzinfo=UTC) .strftime("%Y-%m-%dt%H-%M-%S") ) diff --git a/tests/system/v2_client/test_data_api.py b/tests/system/v2_client/test_data_api.py index e52921771..1e1bf9ce8 100644 --- a/tests/system/v2_client/test_data_api.py +++ b/tests/system/v2_client/test_data_api.py @@ -17,8 +17,6 @@ import pytest -from datetime import timezone - COLUMN_FAMILY_ID1 = "col-fam-id1" COLUMN_FAMILY_ID2 = "col-fam-id2" COL_NAME1 = b"col-name1" @@ -238,7 +236,7 @@ def _write_to_row(row1, row2, row3, row4): from google.cloud._helpers import UTC from google.cloud.bigtable.row_data import Cell - timestamp1 = datetime.datetime.now(timezone.utc).replace(tzinfo=UTC) + timestamp1 = datetime.datetime.now(datetime.UTC) timestamp1_micros = _microseconds_from_datetime(timestamp1) # Truncate to millisecond granularity. timestamp1_micros -= timestamp1_micros % 1000 diff --git a/tests/unit/v2_client/test_backup.py b/tests/unit/v2_client/test_backup.py index b7ecf7b8b..511d7648c 100644 --- a/tests/unit/v2_client/test_backup.py +++ b/tests/unit/v2_client/test_backup.py @@ -20,7 +20,6 @@ from ._testing import _make_credentials from google.cloud._helpers import UTC -from datetime import timezone PROJECT_ID = "project-id" INSTANCE_ID = "instance-id" @@ -39,7 +38,7 @@ def _make_timestamp(): - return datetime.datetime.now(timezone.utc).replace(tzinfo=UTC) + return datetime.datetime.now(datetime.UTC) def _make_table_admin_client(): diff --git a/tests/unit/v2_client/test_cluster.py b/tests/unit/v2_client/test_cluster.py index 445f01611..adc63f2c7 100644 --- a/tests/unit/v2_client/test_cluster.py +++ b/tests/unit/v2_client/test_cluster.py @@ -17,7 +17,6 @@ import pytest from ._testing import _make_credentials -from datetime import timezone PROJECT = "project" INSTANCE_ID = "instance-id" @@ -421,7 +420,7 @@ def test_cluster_create(): from google.cloud.bigtable_admin_v2.types import instance as instance_v2_pb2 from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(timezone.utc) + NOW = datetime.datetime.now(datetime.UTC) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() client = _make_client(project=PROJECT, credentials=credentials, admin=True) @@ -476,7 +475,7 @@ def test_cluster_create_w_cmek(): from google.cloud.bigtable_admin_v2.types import instance as instance_v2_pb2 from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(timezone.utc) + NOW = datetime.datetime.now(datetime.UTC) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() client = _make_client(project=PROJECT, credentials=credentials, admin=True) @@ -536,7 +535,7 @@ def test_cluster_create_w_autoscaling(): from google.cloud.bigtable_admin_v2.types import instance as instance_v2_pb2 from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(timezone.utc) + NOW = datetime.datetime.now(datetime.UTC) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() client = _make_client(project=PROJECT, credentials=credentials, admin=True) @@ -603,7 +602,7 @@ def test_cluster_update(): ) from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(timezone.utc) + NOW = datetime.datetime.now(datetime.UTC) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() @@ -670,7 +669,7 @@ def test_cluster_update_w_autoscaling(): ) from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(timezone.utc) + NOW = datetime.datetime.now(datetime.UTC) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() @@ -729,7 +728,7 @@ def test_cluster_update_w_partial_autoscaling_config(): ) from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(timezone.utc) + NOW = datetime.datetime.now(datetime.UTC) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() @@ -813,7 +812,7 @@ def test_cluster_update_w_both_manual_and_autoscaling(): ) from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(timezone.utc) + NOW = datetime.datetime.now(datetime.UTC) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() @@ -874,7 +873,7 @@ def test_cluster_disable_autoscaling(): from google.cloud.bigtable.instance import Instance from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(timezone.utc) + NOW = datetime.datetime.now(datetime.UTC) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() client = _make_client(project=PROJECT, credentials=credentials, admin=True) diff --git a/tests/unit/v2_client/test_instance.py b/tests/unit/v2_client/test_instance.py index c5ef9c9b8..ecab47e72 100644 --- a/tests/unit/v2_client/test_instance.py +++ b/tests/unit/v2_client/test_instance.py @@ -277,7 +277,7 @@ def _instance_api_response_for_create(): ) from google.cloud.bigtable_admin_v2.types import instance - NOW = datetime.datetime.now(datetime.timezone.utc) + NOW = datetime.datetime.now(datetime.UTC) NOW_PB = _datetime_to_pb_timestamp(NOW) metadata = messages_v2_pb2.CreateInstanceMetadata(request_time=NOW_PB) type_url = "type.googleapis.com/{}".format( @@ -503,7 +503,7 @@ def _instance_api_response_for_update(): ) from google.cloud.bigtable_admin_v2.types import instance - NOW = datetime.datetime.now(datetime.timezone.utc) + NOW = datetime.datetime.now(datetime.UTC) NOW_PB = _datetime_to_pb_timestamp(NOW) metadata = messages_v2_pb2.UpdateInstanceMetadata(request_time=NOW_PB) type_url = "type.googleapis.com/{}".format( diff --git a/tests/unit/v2_client/test_table.py b/tests/unit/v2_client/test_table.py index eab780d63..2d81f3dfb 100644 --- a/tests/unit/v2_client/test_table.py +++ b/tests/unit/v2_client/test_table.py @@ -21,7 +21,6 @@ from google.api_core.exceptions import DeadlineExceeded from ._testing import _make_credentials -from datetime import timezone PROJECT_ID = "project-id" INSTANCE_ID = "instance-id" @@ -1385,7 +1384,7 @@ def test_table_backup_factory_non_defaults(): instance = Instance(INSTANCE_ID, None) table = _make_table(TABLE_ID, instance) - timestamp = datetime.datetime.now(timezone.utc).replace(tzinfo=UTC) + timestamp = datetime.datetime.now(datetime.UTC) backup = table.backup( BACKUP_ID, cluster_id=CLUSTER_ID, From 83d9f1ba263c65a452dadb47eda55ad54fe21a98 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Fri, 30 Jan 2026 14:10:37 -0800 Subject: [PATCH 3/8] removed unneeded import --- tests/system/v2_client/test_data_api.py | 1 - tests/unit/v2_client/test_backup.py | 1 - tests/unit/v2_client/test_table.py | 1 - 3 files changed, 3 deletions(-) diff --git a/tests/system/v2_client/test_data_api.py b/tests/system/v2_client/test_data_api.py index 1e1bf9ce8..85ff63b4f 100644 --- a/tests/system/v2_client/test_data_api.py +++ b/tests/system/v2_client/test_data_api.py @@ -233,7 +233,6 @@ def test_table_read_row_large_cell(data_table, rows_to_delete, skip_on_emulator) def _write_to_row(row1, row2, row3, row4): from google.cloud._helpers import _datetime_from_microseconds from google.cloud._helpers import _microseconds_from_datetime - from google.cloud._helpers import UTC from google.cloud.bigtable.row_data import Cell timestamp1 = datetime.datetime.now(datetime.UTC) diff --git a/tests/unit/v2_client/test_backup.py b/tests/unit/v2_client/test_backup.py index 511d7648c..448ca6fe4 100644 --- a/tests/unit/v2_client/test_backup.py +++ b/tests/unit/v2_client/test_backup.py @@ -19,7 +19,6 @@ import pytest from ._testing import _make_credentials -from google.cloud._helpers import UTC PROJECT_ID = "project-id" INSTANCE_ID = "instance-id" diff --git a/tests/unit/v2_client/test_table.py b/tests/unit/v2_client/test_table.py index 2d81f3dfb..322155bd9 100644 --- a/tests/unit/v2_client/test_table.py +++ b/tests/unit/v2_client/test_table.py @@ -1378,7 +1378,6 @@ def test_table_backup_factory_defaults(): def test_table_backup_factory_non_defaults(): import datetime - from google.cloud._helpers import UTC from google.cloud.bigtable.backup import Backup from google.cloud.bigtable.instance import Instance From f0132b59d44b3fd11b65572813dc421256c554da Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Fri, 30 Jan 2026 15:12:28 -0800 Subject: [PATCH 4/8] use datetime.timezone.utc --- docs/classic_client/snippets.py | 4 ++-- docs/classic_client/snippets_table.py | 19 +++++++++---------- samples/hello/main.py | 2 +- samples/snippets/writes/write_batch.py | 2 +- .../snippets/writes/write_conditionally.py | 2 +- samples/snippets/writes/write_simple.py | 2 +- tests/system/v2_client/_helpers.py | 4 ++-- tests/system/v2_client/test_data_api.py | 2 +- tests/unit/v2_client/test_backup.py | 2 +- tests/unit/v2_client/test_cluster.py | 16 ++++++++-------- tests/unit/v2_client/test_instance.py | 4 ++-- tests/unit/v2_client/test_table.py | 2 +- 12 files changed, 30 insertions(+), 31 deletions(-) diff --git a/docs/classic_client/snippets.py b/docs/classic_client/snippets.py index 81cdd3f7b..f05588542 100644 --- a/docs/classic_client/snippets.py +++ b/docs/classic_client/snippets.py @@ -57,8 +57,8 @@ STORAGE_TYPE = enums.StorageType.SSD LABEL_KEY = "python-snippet" LABEL_STAMP = ( - datetime.datetime.now(datetime.UTC) - .replace(microsecond=0, tzinfo=UTC) + datetime.datetime.now(datetime.timezone.utc) + .replace(microsecond=0) .strftime("%Y-%m-%dt%H-%M-%S") ) LABELS = {LABEL_KEY: str(LABEL_STAMP)} diff --git a/docs/classic_client/snippets_table.py b/docs/classic_client/snippets_table.py index f4c0c4f8f..0217c530c 100644 --- a/docs/classic_client/snippets_table.py +++ b/docs/classic_client/snippets_table.py @@ -37,7 +37,6 @@ from test_utils.system import unique_resource_id from test_utils.retry import RetryErrors -from google.cloud._helpers import UTC from google.cloud.bigtable import Client from google.cloud.bigtable import enums from google.cloud.bigtable import column_family @@ -54,8 +53,8 @@ STORAGE_TYPE = enums.StorageType.SSD LABEL_KEY = "python-snippet" LABEL_STAMP = ( - datetime.datetime.now(datetime.UTC) - .replace(microsecond=0, tzinfo=UTC) + datetime.datetime.now(datetime.timezone.utc) + .replace(microsecond=0) .strftime("%Y-%m-%dt%H-%M-%S") ) LABELS = {LABEL_KEY: str(LABEL_STAMP)} @@ -179,7 +178,7 @@ def test_bigtable_write_read_drop_truncate(): value = "value_{}".format(i).encode() row = table.row(row_key) row.set_cell( - COLUMN_FAMILY_ID, col_name, value, timestamp=datetime.datetime.now(datetime.UTC) + COLUMN_FAMILY_ID, col_name, value, timestamp=datetime.datetime.now(datetime.timezone.utc) ) rows.append(row) response = table.mutate_rows(rows) @@ -270,7 +269,7 @@ def test_bigtable_mutations_batcher(): row_key = row_keys[0] row = table.row(row_key) row.set_cell( - COLUMN_FAMILY_ID, column_name, "value-0", timestamp=datetime.datetime.now(datetime.UTC) + COLUMN_FAMILY_ID, column_name, "value-0", timestamp=datetime.datetime.now(datetime.timezone.utc) ) batcher.mutate(row) # Add a collections of rows @@ -279,7 +278,7 @@ def test_bigtable_mutations_batcher(): row = table.row(row_keys[i]) value = "value_{}".format(i).encode() row.set_cell( - COLUMN_FAMILY_ID, column_name, value, timestamp=datetime.datetime.now(datetime.UTC) + COLUMN_FAMILY_ID, column_name, value, timestamp=datetime.datetime.now(datetime.timezone.utc) ) rows.append(row) batcher.mutate_rows(rows) @@ -759,7 +758,7 @@ def test_bigtable_batcher_mutate_flush_mutate_rows(): row_key = b"row_key_1" row = table.row(row_key) row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, "value-0", timestamp=datetime.datetime.now(datetime.UTC) + COLUMN_FAMILY_ID, COL_NAME1, "value-0", timestamp=datetime.datetime.now(datetime.timezone.utc) ) # In batcher, mutate will flush current batch if it @@ -967,12 +966,12 @@ def test_bigtable_row_data_cells_cell_value_cell_values(): value = b"value_in_col1" row = Config.TABLE.row(b"row_key_1") row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.now(datetime.UTC) + COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.now(datetime.timezone.utc) ) row.commit() row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.now(datetime.UTC) + COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.now(datetime.timezone.utc) ) row.commit() @@ -1050,7 +1049,7 @@ def test_bigtable_row_setcell_rowkey(): cell_val = b"cell-val" row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, cell_val, timestamp=datetime.datetime.now(datetime.UTC) + COLUMN_FAMILY_ID, COL_NAME1, cell_val, timestamp=datetime.datetime.now(datetime.timezone.utc) ) # [END bigtable_api_row_set_cell] diff --git a/samples/hello/main.py b/samples/hello/main.py index aa2dd439c..42fe75095 100644 --- a/samples/hello/main.py +++ b/samples/hello/main.py @@ -88,7 +88,7 @@ def main(project_id, instance_id, table_id): row_key = f"greeting{i}".encode() row = table.direct_row(row_key) row.set_cell( - column_family_id, column, value, timestamp=datetime.datetime.now(datetime.UTC), + column_family_id, column, value, timestamp=datetime.datetime.now(datetime.timezone.utc), ) rows.append(row) table.mutate_rows(rows) diff --git a/samples/snippets/writes/write_batch.py b/samples/snippets/writes/write_batch.py index 2588d01aa..d0e8d1967 100644 --- a/samples/snippets/writes/write_batch.py +++ b/samples/snippets/writes/write_batch.py @@ -25,7 +25,7 @@ def write_batch(project_id, instance_id, table_id): table = instance.table(table_id) with MutationsBatcher(table=table) as batcher: - timestamp = datetime.datetime.now(datetime.UTC) + timestamp = datetime.datetime.now(datetime.timezone.utc) column_family_id = "stats_summary" rows = [ diff --git a/samples/snippets/writes/write_conditionally.py b/samples/snippets/writes/write_conditionally.py index 03a0acdfc..791dd0c3d 100644 --- a/samples/snippets/writes/write_conditionally.py +++ b/samples/snippets/writes/write_conditionally.py @@ -24,7 +24,7 @@ def write_conditional(project_id, instance_id, table_id): instance = client.instance(instance_id) table = instance.table(table_id) - timestamp = datetime.datetime.now(datetime.UTC) + timestamp = datetime.datetime.now(datetime.timezone.utc) column_family_id = "stats_summary" row_key = "phone#4c410523#20190501" diff --git a/samples/snippets/writes/write_simple.py b/samples/snippets/writes/write_simple.py index a7f67731c..4ca56f8fb 100644 --- a/samples/snippets/writes/write_simple.py +++ b/samples/snippets/writes/write_simple.py @@ -24,7 +24,7 @@ def write_simple(project_id, instance_id, table_id): instance = client.instance(instance_id) table = instance.table(table_id) - timestamp = datetime.datetime.now(datetime.UTC) + timestamp = datetime.datetime.now(datetime.timezone.utc) column_family_id = "stats_summary" row_key = "phone#4c410523#20190501" diff --git a/tests/system/v2_client/_helpers.py b/tests/system/v2_client/_helpers.py index 8b7e5ff06..5b78dc07d 100644 --- a/tests/system/v2_client/_helpers.py +++ b/tests/system/v2_client/_helpers.py @@ -41,7 +41,7 @@ def _retry_on_unavailable(exc): def label_stamp(): return ( - datetime.datetime.now(datetime.UTC) - .replace(microsecond=0, tzinfo=UTC) + datetime.datetime.now(datetime.timezone.utc) + .replace(microsecond=0) .strftime("%Y-%m-%dt%H-%M-%S") ) diff --git a/tests/system/v2_client/test_data_api.py b/tests/system/v2_client/test_data_api.py index 85ff63b4f..b1563da1a 100644 --- a/tests/system/v2_client/test_data_api.py +++ b/tests/system/v2_client/test_data_api.py @@ -235,7 +235,7 @@ def _write_to_row(row1, row2, row3, row4): from google.cloud._helpers import _microseconds_from_datetime from google.cloud.bigtable.row_data import Cell - timestamp1 = datetime.datetime.now(datetime.UTC) + timestamp1 = datetime.datetime.now(datetime.timezone.utc) timestamp1_micros = _microseconds_from_datetime(timestamp1) # Truncate to millisecond granularity. timestamp1_micros -= timestamp1_micros % 1000 diff --git a/tests/unit/v2_client/test_backup.py b/tests/unit/v2_client/test_backup.py index 448ca6fe4..a5d205af6 100644 --- a/tests/unit/v2_client/test_backup.py +++ b/tests/unit/v2_client/test_backup.py @@ -37,7 +37,7 @@ def _make_timestamp(): - return datetime.datetime.now(datetime.UTC) + return datetime.datetime.now(datetime.timezone.utc) def _make_table_admin_client(): diff --git a/tests/unit/v2_client/test_cluster.py b/tests/unit/v2_client/test_cluster.py index adc63f2c7..a21104549 100644 --- a/tests/unit/v2_client/test_cluster.py +++ b/tests/unit/v2_client/test_cluster.py @@ -420,7 +420,7 @@ def test_cluster_create(): from google.cloud.bigtable_admin_v2.types import instance as instance_v2_pb2 from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(datetime.UTC) + NOW = datetime.datetime.now(datetime.timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() client = _make_client(project=PROJECT, credentials=credentials, admin=True) @@ -475,7 +475,7 @@ def test_cluster_create_w_cmek(): from google.cloud.bigtable_admin_v2.types import instance as instance_v2_pb2 from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(datetime.UTC) + NOW = datetime.datetime.now(datetime.timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() client = _make_client(project=PROJECT, credentials=credentials, admin=True) @@ -535,7 +535,7 @@ def test_cluster_create_w_autoscaling(): from google.cloud.bigtable_admin_v2.types import instance as instance_v2_pb2 from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(datetime.UTC) + NOW = datetime.datetime.now(datetime.timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() client = _make_client(project=PROJECT, credentials=credentials, admin=True) @@ -602,7 +602,7 @@ def test_cluster_update(): ) from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(datetime.UTC) + NOW = datetime.datetime.now(datetime.timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() @@ -669,7 +669,7 @@ def test_cluster_update_w_autoscaling(): ) from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(datetime.UTC) + NOW = datetime.datetime.now(datetime.timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() @@ -728,7 +728,7 @@ def test_cluster_update_w_partial_autoscaling_config(): ) from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(datetime.UTC) + NOW = datetime.datetime.now(datetime.timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() @@ -812,7 +812,7 @@ def test_cluster_update_w_both_manual_and_autoscaling(): ) from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(datetime.UTC) + NOW = datetime.datetime.now(datetime.timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() @@ -873,7 +873,7 @@ def test_cluster_disable_autoscaling(): from google.cloud.bigtable.instance import Instance from google.cloud.bigtable.enums import StorageType - NOW = datetime.datetime.now(datetime.UTC) + NOW = datetime.datetime.now(datetime.timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) credentials = _make_credentials() client = _make_client(project=PROJECT, credentials=credentials, admin=True) diff --git a/tests/unit/v2_client/test_instance.py b/tests/unit/v2_client/test_instance.py index ecab47e72..c5ef9c9b8 100644 --- a/tests/unit/v2_client/test_instance.py +++ b/tests/unit/v2_client/test_instance.py @@ -277,7 +277,7 @@ def _instance_api_response_for_create(): ) from google.cloud.bigtable_admin_v2.types import instance - NOW = datetime.datetime.now(datetime.UTC) + NOW = datetime.datetime.now(datetime.timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) metadata = messages_v2_pb2.CreateInstanceMetadata(request_time=NOW_PB) type_url = "type.googleapis.com/{}".format( @@ -503,7 +503,7 @@ def _instance_api_response_for_update(): ) from google.cloud.bigtable_admin_v2.types import instance - NOW = datetime.datetime.now(datetime.UTC) + NOW = datetime.datetime.now(datetime.timezone.utc) NOW_PB = _datetime_to_pb_timestamp(NOW) metadata = messages_v2_pb2.UpdateInstanceMetadata(request_time=NOW_PB) type_url = "type.googleapis.com/{}".format( diff --git a/tests/unit/v2_client/test_table.py b/tests/unit/v2_client/test_table.py index 322155bd9..6b31a5e23 100644 --- a/tests/unit/v2_client/test_table.py +++ b/tests/unit/v2_client/test_table.py @@ -1383,7 +1383,7 @@ def test_table_backup_factory_non_defaults(): instance = Instance(INSTANCE_ID, None) table = _make_table(TABLE_ID, instance) - timestamp = datetime.datetime.now(datetime.UTC) + timestamp = datetime.datetime.now(datetime.timezone.utc) backup = table.backup( BACKUP_ID, cluster_id=CLUSTER_ID, From 43bab5a0cdf937eb432099efa3f5b26bddce71e0 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Fri, 30 Jan 2026 15:17:37 -0800 Subject: [PATCH 5/8] removed unused import --- tests/system/v2_client/_helpers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/system/v2_client/_helpers.py b/tests/system/v2_client/_helpers.py index 5b78dc07d..e6fe10343 100644 --- a/tests/system/v2_client/_helpers.py +++ b/tests/system/v2_client/_helpers.py @@ -17,7 +17,6 @@ import grpc from google.api_core import exceptions from google.cloud import exceptions as core_exceptions -from google.cloud._helpers import UTC from test_utils import retry From 119a1b0bf9347f2c1e3ee1cca8040c70251fc935 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 3 Feb 2026 12:16:03 -0800 Subject: [PATCH 6/8] changed import --- docs/classic_client/snippets.py | 6 +++--- docs/classic_client/snippets_table.py | 18 +++++++++--------- samples/hello/main.py | 4 ++-- samples/snippets/writes/write_batch.py | 4 ++-- samples/snippets/writes/write_conditionally.py | 4 ++-- samples/snippets/writes/write_simple.py | 4 ++-- tests/system/v2_client/_helpers.py | 4 ++-- tests/system/v2_client/test_data_api.py | 4 ++-- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/classic_client/snippets.py b/docs/classic_client/snippets.py index f05588542..c6059409d 100644 --- a/docs/classic_client/snippets.py +++ b/docs/classic_client/snippets.py @@ -29,7 +29,7 @@ """ -import datetime +from datetime import datetime, timezone import pytest from google.api_core.exceptions import DeadlineExceeded @@ -39,7 +39,7 @@ from test_utils.system import unique_resource_id from test_utils.retry import RetryErrors -from google.cloud._helpers import UTC + from google.cloud.bigtable import Client from google.cloud.bigtable import enums @@ -57,7 +57,7 @@ STORAGE_TYPE = enums.StorageType.SSD LABEL_KEY = "python-snippet" LABEL_STAMP = ( - datetime.datetime.now(datetime.timezone.utc) + datetime.now(timezone.utc) .replace(microsecond=0) .strftime("%Y-%m-%dt%H-%M-%S") ) diff --git a/docs/classic_client/snippets_table.py b/docs/classic_client/snippets_table.py index 0217c530c..1850e836b 100644 --- a/docs/classic_client/snippets_table.py +++ b/docs/classic_client/snippets_table.py @@ -29,7 +29,7 @@ """ -import datetime +from datetime import datetime, timezone import pytest from google.api_core.exceptions import TooManyRequests @@ -53,7 +53,7 @@ STORAGE_TYPE = enums.StorageType.SSD LABEL_KEY = "python-snippet" LABEL_STAMP = ( - datetime.datetime.now(datetime.timezone.utc) + datetime.now(timezone.utc) .replace(microsecond=0) .strftime("%Y-%m-%dt%H-%M-%S") ) @@ -178,7 +178,7 @@ def test_bigtable_write_read_drop_truncate(): value = "value_{}".format(i).encode() row = table.row(row_key) row.set_cell( - COLUMN_FAMILY_ID, col_name, value, timestamp=datetime.datetime.now(datetime.timezone.utc) + COLUMN_FAMILY_ID, col_name, value, timestamp=datetime.now(timezone.utc) ) rows.append(row) response = table.mutate_rows(rows) @@ -269,7 +269,7 @@ def test_bigtable_mutations_batcher(): row_key = row_keys[0] row = table.row(row_key) row.set_cell( - COLUMN_FAMILY_ID, column_name, "value-0", timestamp=datetime.datetime.now(datetime.timezone.utc) + COLUMN_FAMILY_ID, column_name, "value-0", timestamp=datetime.now(timezone.utc) ) batcher.mutate(row) # Add a collections of rows @@ -278,7 +278,7 @@ def test_bigtable_mutations_batcher(): row = table.row(row_keys[i]) value = "value_{}".format(i).encode() row.set_cell( - COLUMN_FAMILY_ID, column_name, value, timestamp=datetime.datetime.now(datetime.timezone.utc) + COLUMN_FAMILY_ID, column_name, value, timestamp=datetime.now(timezone.utc) ) rows.append(row) batcher.mutate_rows(rows) @@ -758,7 +758,7 @@ def test_bigtable_batcher_mutate_flush_mutate_rows(): row_key = b"row_key_1" row = table.row(row_key) row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, "value-0", timestamp=datetime.datetime.now(datetime.timezone.utc) + COLUMN_FAMILY_ID, COL_NAME1, "value-0", timestamp=datetime.now(timezone.utc) ) # In batcher, mutate will flush current batch if it @@ -966,12 +966,12 @@ def test_bigtable_row_data_cells_cell_value_cell_values(): value = b"value_in_col1" row = Config.TABLE.row(b"row_key_1") row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.now(datetime.timezone.utc) + COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.now(timezone.utc) ) row.commit() row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.now(datetime.timezone.utc) + COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.now(timezone.utc) ) row.commit() @@ -1049,7 +1049,7 @@ def test_bigtable_row_setcell_rowkey(): cell_val = b"cell-val" row.set_cell( - COLUMN_FAMILY_ID, COL_NAME1, cell_val, timestamp=datetime.datetime.now(datetime.timezone.utc) + COLUMN_FAMILY_ID, COL_NAME1, cell_val, timestamp=datetime.now(timezone.utc) ) # [END bigtable_api_row_set_cell] diff --git a/samples/hello/main.py b/samples/hello/main.py index 42fe75095..b471771e4 100644 --- a/samples/hello/main.py +++ b/samples/hello/main.py @@ -28,7 +28,7 @@ from ..utils import wait_for_table # [START bigtable_hw_imports] -import datetime +from datetime import datetime, timezone from google.cloud import bigtable from google.cloud.bigtable import column_family @@ -88,7 +88,7 @@ def main(project_id, instance_id, table_id): row_key = f"greeting{i}".encode() row = table.direct_row(row_key) row.set_cell( - column_family_id, column, value, timestamp=datetime.datetime.now(datetime.timezone.utc), + column_family_id, column, value, timestamp=datetime.now(timezone.utc), ) rows.append(row) table.mutate_rows(rows) diff --git a/samples/snippets/writes/write_batch.py b/samples/snippets/writes/write_batch.py index d0e8d1967..a583bb713 100644 --- a/samples/snippets/writes/write_batch.py +++ b/samples/snippets/writes/write_batch.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # [START bigtable_writes_batch] -import datetime +from datetime import datetime, timezone from google.cloud import bigtable from google.cloud.bigtable.batcher import MutationsBatcher @@ -25,7 +25,7 @@ def write_batch(project_id, instance_id, table_id): table = instance.table(table_id) with MutationsBatcher(table=table) as batcher: - timestamp = datetime.datetime.now(datetime.timezone.utc) + timestamp = datetime.now(timezone.utc) column_family_id = "stats_summary" rows = [ diff --git a/samples/snippets/writes/write_conditionally.py b/samples/snippets/writes/write_conditionally.py index 791dd0c3d..b6f05fba7 100644 --- a/samples/snippets/writes/write_conditionally.py +++ b/samples/snippets/writes/write_conditionally.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # [START bigtable_writes_conditional] -import datetime +from datetime import datetime, timezone from google.cloud import bigtable from google.cloud.bigtable import row_filters @@ -24,7 +24,7 @@ def write_conditional(project_id, instance_id, table_id): instance = client.instance(instance_id) table = instance.table(table_id) - timestamp = datetime.datetime.now(datetime.timezone.utc) + timestamp = datetime.now(timezone.utc) column_family_id = "stats_summary" row_key = "phone#4c410523#20190501" diff --git a/samples/snippets/writes/write_simple.py b/samples/snippets/writes/write_simple.py index 4ca56f8fb..fb7074bc5 100644 --- a/samples/snippets/writes/write_simple.py +++ b/samples/snippets/writes/write_simple.py @@ -14,7 +14,7 @@ # limitations under the License. # [START bigtable_writes_simple] -import datetime +from datetime import datetime, timezone from google.cloud import bigtable @@ -24,7 +24,7 @@ def write_simple(project_id, instance_id, table_id): instance = client.instance(instance_id) table = instance.table(table_id) - timestamp = datetime.datetime.now(datetime.timezone.utc) + timestamp = datetime.now(timezone.utc) column_family_id = "stats_summary" row_key = "phone#4c410523#20190501" diff --git a/tests/system/v2_client/_helpers.py b/tests/system/v2_client/_helpers.py index e6fe10343..60d157247 100644 --- a/tests/system/v2_client/_helpers.py +++ b/tests/system/v2_client/_helpers.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import datetime +from datetime import datetime, timezone import grpc from google.api_core import exceptions @@ -40,7 +40,7 @@ def _retry_on_unavailable(exc): def label_stamp(): return ( - datetime.datetime.now(datetime.timezone.utc) + datetime.now(timezone.utc) .replace(microsecond=0) .strftime("%Y-%m-%dt%H-%M-%S") ) diff --git a/tests/system/v2_client/test_data_api.py b/tests/system/v2_client/test_data_api.py index b1563da1a..d0acb0671 100644 --- a/tests/system/v2_client/test_data_api.py +++ b/tests/system/v2_client/test_data_api.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import datetime +import datetime, timezone import operator import pytest @@ -235,7 +235,7 @@ def _write_to_row(row1, row2, row3, row4): from google.cloud._helpers import _microseconds_from_datetime from google.cloud.bigtable.row_data import Cell - timestamp1 = datetime.datetime.now(datetime.timezone.utc) + timestamp1 = datetime.now(timezone.utc) timestamp1_micros = _microseconds_from_datetime(timestamp1) # Truncate to millisecond granularity. timestamp1_micros -= timestamp1_micros % 1000 From 8e6d54303155eb895cef35caf4c9c22e69947472 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 3 Feb 2026 12:19:51 -0800 Subject: [PATCH 7/8] fixed import --- tests/system/v2_client/_helpers.py | 4 +--- tests/system/v2_client/test_data_api.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/system/v2_client/_helpers.py b/tests/system/v2_client/_helpers.py index 60d157247..e792def15 100644 --- a/tests/system/v2_client/_helpers.py +++ b/tests/system/v2_client/_helpers.py @@ -40,7 +40,5 @@ def _retry_on_unavailable(exc): def label_stamp(): return ( - datetime.now(timezone.utc) - .replace(microsecond=0) - .strftime("%Y-%m-%dt%H-%M-%S") + datetime.now(timezone.utc).replace(microsecond=0).strftime("%Y-%m-%dt%H-%M-%S") ) diff --git a/tests/system/v2_client/test_data_api.py b/tests/system/v2_client/test_data_api.py index d0acb0671..6fcaa4858 100644 --- a/tests/system/v2_client/test_data_api.py +++ b/tests/system/v2_client/test_data_api.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import datetime, timezone +from datetime import datetime, timezone import operator import pytest From b98043f7fb7e887202f2f61a00d786b0decd72c7 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 3 Feb 2026 12:24:37 -0800 Subject: [PATCH 8/8] fixed test --- tests/system/v2_client/test_data_api.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/system/v2_client/test_data_api.py b/tests/system/v2_client/test_data_api.py index 6fcaa4858..c012eb32a 100644 --- a/tests/system/v2_client/test_data_api.py +++ b/tests/system/v2_client/test_data_api.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from datetime import datetime, timezone +from datetime import datetime, timedelta, timezone import operator import pytest @@ -62,8 +62,8 @@ def rows_to_delete(): def test_table_read_rows_filter_millis(data_table): from google.cloud.bigtable import row_filters - end = datetime.datetime.now() - start = end - datetime.timedelta(minutes=60) + end = datetime.now() + start = end - timedelta(minutes=60) timestamp_range = row_filters.TimestampRange(start=start, end=end) timefilter = row_filters.TimestampRangeFilter(timestamp_range) row_data = data_table.read_rows(filter_=timefilter) @@ -241,11 +241,11 @@ def _write_to_row(row1, row2, row3, row4): timestamp1_micros -= timestamp1_micros % 1000 timestamp1 = _datetime_from_microseconds(timestamp1_micros) # 1000 microseconds is a millisecond - timestamp2 = timestamp1 + datetime.timedelta(microseconds=1000) + timestamp2 = timestamp1 + timedelta(microseconds=1000) timestamp2_micros = _microseconds_from_datetime(timestamp2) - timestamp3 = timestamp1 + datetime.timedelta(microseconds=2000) + timestamp3 = timestamp1 + timedelta(microseconds=2000) timestamp3_micros = _microseconds_from_datetime(timestamp3) - timestamp4 = timestamp1 + datetime.timedelta(microseconds=3000) + timestamp4 = timestamp1 + timedelta(microseconds=3000) timestamp4_micros = _microseconds_from_datetime(timestamp4) if row1 is not None: