Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: increment seqno before execute calls to prevent InvalidArgument … #19

Merged
merged 9 commits into from Mar 24, 2020
5 changes: 2 additions & 3 deletions google/cloud/spanner_v1/snapshot.py
Expand Up @@ -225,12 +225,11 @@ def execute_sql(
retry=retry,
timeout=timeout,
)

iterator = _restart_on_unavailable(restart)

self._read_request_count += 1
self._execute_sql_count += 1

iterator = _restart_on_unavailable(restart)

if self._multi_use:
return StreamedResultSet(iterator, source=self)
else:
Expand Down
14 changes: 8 additions & 6 deletions google/cloud/spanner_v1/transaction.py
Expand Up @@ -191,18 +191,19 @@ def execute_update(self, dml, params=None, param_types=None, query_mode=None):
transaction = self._make_txn_selector()
api = database.spanner_api

seqno = self._execute_sql_count
self._execute_sql_count += 1
larkee marked this conversation as resolved.
Show resolved Hide resolved

response = api.execute_sql(
self._session.name,
dml,
transaction=transaction,
params=params_pb,
param_types=param_types,
query_mode=query_mode,
seqno=self._execute_sql_count,
seqno=seqno,
metadata=metadata,
)

self._execute_sql_count += 1
return response.stats.row_count_exact

def batch_update(self, statements):
Expand Down Expand Up @@ -243,15 +244,16 @@ def batch_update(self, statements):
transaction = self._make_txn_selector()
api = database.spanner_api

seqno = self._execute_sql_count
self._execute_sql_count += 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise here:

        seqno, self._execute_sql_count = self._execute_sql_count, self._execute_sql_count + 1


response = api.execute_batch_dml(
session=self._session.name,
transaction=transaction,
statements=parsed,
seqno=self._execute_sql_count,
seqno=seqno,
metadata=metadata,
)

self._execute_sql_count += 1
row_counts = [
result_set.stats.row_count_exact for result_set in response.result_sets
]
Expand Down