GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat(dbapi): wire timeout parameter through Connection to execute_sql by waiho-gumloop · Pull Request #1535 · googleapis/python-spanner
This repository was archived by the owner on Jun 8, 2026. It is now read-only.
Conversation
|
| Date | Commit | Event |
|---|---|---|
| Nov 2018 | 9b7fcd6 (PR #6536) |
timeout= parameter added to _SnapshotBase.execute_sql() in the Spanner client |
| Nov 2020 | 2493fa1 (PR #160) |
DBAPI created — cursor._handle_DQL_with_snapshot() calls execute_sql() without timeout= |
| Nov 2020 | d59d502 (PR #168) |
connection.run_statement() added — calls execute_sql() without timeout= |
| Mar 2021 | 1a7c9d2 (PR #278) |
timeout= expanded to read(), partition_read(), partition_query() in the client |
| Oct 2021 | cd3b950 (PR #475) |
_handle_DQL_with_snapshot() extracted as separate method — still no timeout= |
| Oct 2022 | ab768e4 (PR #838) |
request_options added to _handle_DQL_with_snapshot() — timeout= not added |
| Jan 2025 | ee9662f (PR #1262) |
request_tag/transaction_tag added to cursor/connection — timeout= not added |
Other execution parameters (request_options, request_priority, transaction_tag, request_tag) were each wired through the DBAPI incrementally. The timeout parameter was not included in any of these additions.
connection.pyself._timeout = None to __init__timeout property and settertimeout=self._timeout in run_statement() when setcursor.pytimeout=self.connection._timeout in _handle_DQL_with_snapshot() when settimeout=self.connection._timeout in _do_execute_update_in_autocommit() when setWhen timeout is None (the default), timeout= is not passed, preserving the existing behavior of using gapic_v1.method.DEFAULT.
from google.cloud.spanner_dbapi import connect conn = connect(instance_id, database_id, project=project) conn.timeout = 60 # 60-second gRPC deadline for subsequent statements cursor = conn.cursor() cursor.execute("SELECT * FROM my_table")
Added 7 unit tests:
test_timeout_default_none — verifies default is Nonetest_timeout_property — verifies getter/settertest_timeout_passed_to_run_statement — verifies timeout= is passed in run_statement()test_timeout_not_passed_when_none — verifies timeout= is omitted when Nonetest_do_execute_update_with_timeout — verifies timeout= in autocommit DML pathtest_handle_DQL_with_snapshot_timeout — verifies timeout= in snapshot read pathtest_handle_DQL_with_snapshot_no_timeout — verifies omission in snapshot read pathAll 205 existing DBAPI tests continue to pass.
timeout= on execute_sql(): PR chore: add samples for transaction timeout configuration #1380 (spanner_set_statement_timeout), PR feat: add retry and timeout for batch dml #1107 (spanner_set_custom_timeout_and_retry)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This pull request introduces a timeout property to the Connection class in the Spanner DB-API, allowing users to set a gRPC deadline for SQL operations. The timeout value is propagated to execute_sql calls in run_statement, _do_execute_update_in_autocommit, and _handle_DQL_with_snapshot. Corresponding unit tests have been added to verify the property behavior and its correct application during execution. Feedback suggests refactoring the execute_sql call in _handle_DQL_with_snapshot to use a consistent keyword argument pattern for param_types, matching other updated call sites.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| kwargs = dict(request_options=self.request_options) | ||
| if self.connection._timeout is not None: | ||
| kwargs["timeout"] = self.connection._timeout | ||
| self._result_set = snapshot.execute_sql( | ||
| sql, | ||
| params, | ||
| get_param_types(params), | ||
| request_options=self.request_options, | ||
| **kwargs, | ||
| ) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
For consistency with the changes in run_statement and _do_execute_update_in_autocommit, consider including param_types in the kwargs dictionary instead of passing it as a positional argument. This would make all three modified call sites for execute_sql follow the same pattern, improving maintainability.
| kwargs = dict(request_options=self.request_options) | |
| if self.connection._timeout is not None: | |
| kwargs["timeout"] = self.connection._timeout | |
| self._result_set = snapshot.execute_sql( | |
| sql, | |
| params, | |
| get_param_types(params), | |
| request_options=self.request_options, | |
| **kwargs, | |
| ) | |
| kwargs = dict( | |
| param_types=get_param_types(params), | |
| request_options=self.request_options, | |
| ) | |
| if self.connection._timeout is not None: | |
| kwargs["timeout"] = self.connection._timeout | |
| self._result_set = snapshot.execute_sql( | |
| sql, | |
| params, | |
| **kwargs, | |
| ) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The DBAPI layer calls _SnapshotBase.execute_sql() in three code paths (snapshot reads, transaction reads/writes, autocommit DML) but never passes the timeout= argument. This causes all queries to use the gRPC default timeout of 3600 seconds. Add a timeout property to Connection and pass it through to execute_sql() in cursor._handle_DQL_with_snapshot(), cursor._do_execute_update_in_autocommit(), and connection.run_statement(). Fixes #1534
b73fa31 to
f93bed6
Compare
|
Hi @waiho-gumloop, The code in this repository has moved to https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-spanner. Please could you open a new PR in google-cloud-python? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
feat(dbapi): wire timeout parameter through to execute_sql in cursor and connection
There was an error while loading. Please reload this page.