Skip to content

Commit

Permalink
fix(spanner): use future date to avoid time drift (#4471)
Browse files Browse the repository at this point in the history
fixes #4197
  • Loading branch information
Takashi Matsuo authored Aug 13, 2020
1 parent 32a52dd commit b523300
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 7 additions & 0 deletions spanner/cloud-client/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,13 @@ def query_data_with_timestamp_parameter(instance_id, database_id):
database = instance.database(database_id)

example_timestamp = datetime.datetime.utcnow().isoformat() + "Z"
# [END spanner_query_with_timestamp_parameter]
# Avoid time drift on the local machine.
# https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4197.
example_timestamp = (
datetime.datetime.utcnow() + datetime.timedelta(days=1)
).isoformat() + "Z"
# [START spanner_query_with_timestamp_parameter]
param = {
'last_update_time': example_timestamp
}
Expand Down
3 changes: 0 additions & 3 deletions spanner/cloud-client/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,6 @@ def test_query_data_with_string(capsys):


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

0 comments on commit b523300

Please sign in to comment.