-
Notifications
You must be signed in to change notification settings - Fork 116
Skip the result cache for qmark queries with parameters #959
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1280,7 +1280,8 @@ def _execute( | |
| """Start a query execution, or find a previous one to reuse. | ||
|
|
||
| The individual keyword arguments override the ``options`` field of the | ||
| same name unless None. | ||
| same name unless None. A query with execution parameters (``qmark``) | ||
| always starts a new execution. | ||
|
|
||
| Args: | ||
| operation: SQL query string. | ||
|
|
@@ -1317,12 +1318,16 @@ def _execute( | |
| paramstyle=paramstyle, | ||
| ) | ||
| query, request = self._build_execute_request(operation, parameters, options) | ||
| query_id = self._find_previous_query_id( | ||
| query, | ||
| options.work_group, | ||
| cache_size=options.cache_size, | ||
| cache_expiration_time=options.cache_expiration_time, | ||
| ) | ||
| query_id = None | ||
| # Athena does not return the ExecutionParameters of earlier executions, | ||
| # so the cache cannot tell which parameters an execution ran with (#941). | ||
| if not request.get("ExecutionParameters"): | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Self-review round 1 (implementation behavior) — FINDINGS (1, repaired) Scope: base e0e85da, reviewed head 9126987; all 6 changed files. Covered:
Finding: the added Deferred (pre-existing, not introduced): a |
||
| query_id = self._find_previous_query_id( | ||
| query, | ||
| options.work_group, | ||
| cache_size=options.cache_size, | ||
| cache_expiration_time=options.cache_expiration_time, | ||
| ) | ||
| if query_id is None: | ||
| query_id = self._start_execution(lambda: self._start_query_execution(request)) | ||
| return query_id | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,6 +199,24 @@ def test_cache_size_with_work_group(self, cursor): | |
| assert first_query_id != second_query_id | ||
| assert third_query_id in [first_query_id, second_query_id] | ||
|
|
||
| @pytest.mark.parametrize("cursor", [{"work_group": ENV.work_group}], indirect=["cursor"]) | ||
| def test_cache_size_with_qmark_parameters(self, cursor): | ||
| query = f"SELECT ? AS v -- {datetime.now(UTC)!s}" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent review (relayed) — FINDINGS (2; 1 rejected with evidence, 1 pre-existing and deferred) Reviewer: Codex CLI 0.160.0, model Covered (reviewer): the full diff; all sync, threaded-async, and aio SQL cursor paths (Dict, pandas, Arrow, Polars, S3FS); UNLOAD; legacy private-method signatures; cache matching; changed docs; relevant tests. The reviewer confirmed that the guard reaches every applicable cursor, private signatures are preserved, both mocked tests fail against the original code, and botocore's service documentation says the parameters are not returned.
No code change resulted, so no follow-up review is needed. The PR description now also quotes botocore's field documentation. |
||
|
|
||
| cursor.execute(query, ["'1'"], paramstyle="qmark") | ||
| first_query_id = cursor.query_id | ||
|
|
||
| # Different parameters must not reuse the earlier execution (#941). | ||
| cursor.execute(query, ["'2'"], paramstyle="qmark", cache_size=100) | ||
| assert cursor.query_id != first_query_id | ||
| assert cursor.fetchall() == [("2",)] | ||
|
|
||
| # Athena does not return the parameters of earlier executions, | ||
| # so even the same parameters run again. | ||
| cursor.execute(query, ["'1'"], paramstyle="qmark", cache_size=100) | ||
| assert cursor.query_id != first_query_id | ||
| assert cursor.fetchall() == [("1",)] | ||
|
|
||
| def test_cache_expiration_time(self, cursor): | ||
| query = f"SELECT * FROM one_row -- {datetime.now(UTC)!s}" | ||
|
|
||
|
|
@@ -1303,6 +1321,32 @@ def test_execute_internal_legacy_kwargs_passthrough(self): | |
| cache_expiration_time=100, | ||
| ) | ||
|
|
||
| def test_execute_qmark_parameters_skip_cache(self): | ||
| """A qmark query with parameters never searches the cache (no AWS, #941).""" | ||
| cursor = Cursor.__new__(Cursor) # bypass __init__ to avoid AWS calls | ||
| cursor._connection = MagicMock() | ||
| cursor._connection.client.start_query_execution.return_value = { | ||
| "QueryExecutionId": "test_query_id" | ||
| } | ||
| cursor._retry_config = RetryConfig() | ||
| cursor._kill_on_interrupt = True | ||
|
|
||
| with ( | ||
| patch.object( | ||
| Cursor, | ||
| "_build_start_query_execution_request", | ||
| return_value={"ExecutionParameters": ["'1'"]}, | ||
| ) as request_mock, | ||
| patch.object(Cursor, "_find_previous_query_id", return_value="cached") as cache_mock, | ||
| ): | ||
| query_id = cursor._execute( | ||
| "SELECT ?", ["'1'"], paramstyle="qmark", cache_size=10, cache_expiration_time=100 | ||
| ) | ||
|
|
||
| assert query_id == "test_query_id" | ||
| assert request_mock.call_args.kwargs["execution_parameters"] == ["'1'"] | ||
| cache_mock.assert_not_called() | ||
|
|
||
| def test_connection_level_callback(self): | ||
| """Test connection-level default callback.""" | ||
| callback_results = [] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self-review round 2 (claims, compatibility, operations) — FINDINGS (PR description only, corrected)
Scope: base e0e85da, head 9f3557c; claims in the PR body, commit messages, this comment, the
_execute()/ExecuteOptions.cache_sizedocstrings,docs/usage.md:289, and the issue premise.Claims checked:
AthenaQueryExecution.execution_parametersexposes them" — false in practice. Measured 2026-10-03 in work groupspyathenaandprimary: neitherGetQueryExecutionnorBatchGetQueryExecution(the API the cache search uses) returnsExecutionParametersfor a query started with them, although botocore 1.43.102'sQueryExecutionshape declares the field. This comment's claim holds for both measured work groups.SELECT ? AS vwithparamstyle="qmark"and no parameters fails withINVALID_PARAMETER_USAGE: Incorrect number of parameters: expected 1 but found 0, so the remaining pre-existing match only affects invalid calls.pyformat, keep the existing behavior":_build_start_query_execution_request()addsExecutionParametersonly for a non-empty list;pyformatpassesNone.docs/usage.md:108-143) says nothing about caching; the cache section now states the rule; no other doc mentionsqmarkwith the cache.qmarkqueries with identical parameters used to get correct cache hits and now run again (more Athena queries for those callers). This was missing from the release note.ListQueryExecutions/BatchGetQueryExecutioncalls; no retry layer changes.Corrections to the PR description: named the second measured work group, added the identical-parameters behavior change to the release note, and stated which commit the test results belong to.