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

Skip to content

Commit b523300

Browse files
author
Takashi Matsuo
authored
fix(spanner): use future date to avoid time drift (GoogleCloudPlatform#4471)
fixes GoogleCloudPlatform#4197
1 parent 32a52dd commit b523300

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

spanner/cloud-client/snippets.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,13 @@ def query_data_with_timestamp_parameter(instance_id, database_id):
14071407
database = instance.database(database_id)
14081408

14091409
example_timestamp = datetime.datetime.utcnow().isoformat() + "Z"
1410+
# [END spanner_query_with_timestamp_parameter]
1411+
# Avoid time drift on the local machine.
1412+
# https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4197.
1413+
example_timestamp = (
1414+
datetime.datetime.utcnow() + datetime.timedelta(days=1)
1415+
).isoformat() + "Z"
1416+
# [START spanner_query_with_timestamp_parameter]
14101417
param = {
14111418
'last_update_time': example_timestamp
14121419
}

spanner/cloud-client/snippets_test.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,6 @@ def test_query_data_with_string(capsys):
363363

364364

365365
def test_query_data_with_timestamp_parameter(capsys):
366-
# Wait 5 seconds to avoid a time drift issue for the next query:
367-
# https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4197.
368-
time.sleep(5)
369366
snippets.query_data_with_timestamp_parameter(INSTANCE_ID, DATABASE_ID)
370367
out, _ = capsys.readouterr()
371368
assert 'VenueId: 4, VenueName: Venue 4, LastUpdateTime:' in out

0 commit comments

Comments
 (0)