| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
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.
| 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.
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.
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
|
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.
| Back | FazBrowse Home | New Git URL |
Summary
Add a timeout property to Connection and pass timeout= to execute_sql() in the three DBAPI code paths that currently omit it: snapshot reads, transaction statements, and autocommit DML.
Fixes googleapis/google-cloud-python#16492
Background
_SnapshotBase.execute_sql() accepts a timeout parameter that controls the gRPC deadline for the ExecuteStreamingSql RPC. When not provided, it defaults to gapic_v1.method.DEFAULT, which resolves to default_timeout=3600.0 in the transport layer.
The DBAPI calls execute_sql() in three locations, none of which pass timeout=:
This means DBAPI consumers (SQLAlchemy, Django, raw DBAPI) cannot control the gRPC deadline for individual statements — all queries use the 3600-second default.
Timeline
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.
Changes
connection.py
cursor.py
When timeout is None (the default), timeout= is not passed, preserving the existing behavior of using gapic_v1.method.DEFAULT.
Usage
Tests
Added 7 unit tests:
All 205 existing DBAPI tests continue to pass.
Related