Stop throwing an error in an attempt to stop an already failed statement - #209
Draft
James Robinson (jlrobins) wants to merge 1 commit into
Draft
Stop throwing an error in an attempt to stop an already failed statement #209James Robinson (jlrobins) wants to merge 1 commit into
James Robinson (jlrobins) wants to merge 1 commit into
Conversation
…ent --- stopping already terminal state statements result in a no-op.
Copilot started reviewing on behalf of
James Robinson (jlrobins)
September 4, 2026 20:31
View session
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The behavior change is narrowly scoped, matches the documented API semantics, and is covered by both unit and integration regression tests.
Pull request overview
This PR fixes Connection.stop_statement(wait_for_stopped=True) so stopping a statement that is already in a terminal phase (specifically FAILED before the stop was requested) is treated as a successful no-op rather than raising OperationalError, aligning the bare-name path with the existing Statement-object short-circuit behavior.
Changes:
- Reorders the terminal-phase vs. failed-phase checks in
_wait_for_statement_stoppedso an already-terminalFAILEDstatement returns successfully without polling. - Adds unit and integration regression tests covering the “already FAILED before stop” scenario and reinforces the “already STOPPED is a no-op” behavior for both name/object paths.
- Updates docstrings and the changelog to document the corrected behavior.
File summaries
| File | Description |
|---|---|
src/confluent_sql/connection.py |
Adjusts _wait_for_statement_stopped to short-circuit on terminal phases (including already-FAILED) before raising on mid-wait transitions to FAILED; expands docstrings to reflect idempotent server behavior. |
tests/unit/test_connection_unit.py |
Adds a unit regression test ensuring no polling occurs when the stop PATCH response is already FAILED. |
tests/integration/test_connection.py |
Adds an integration regression test for stopping a statement that fails on its own (SELECT 1/0) and reinforces no-op stopping behavior for already-stopped statements by name. |
CHANGELOG.md |
Documents the behavioral fix for #203 in the Unreleased “Fixed” section. |
Review details
Suppressed comments (1)
src/confluent_sql/connection.py:1363
- The timeout OperationalError message says the statement did not reach STOPPED, but this helper now treats any terminal phase as success; the message should reflect waiting for a terminal phase to avoid misleading callers when a statement completes/gets deleted etc.
if statement.phase.is_terminal:
return statement
for _ in sleep_with_backoff(timeout):
statement = self.get_statement(statement.name)
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+407
to
+413
| """The actual bug behind #203: a statement that reached FAILED on its own (not via | ||
| stop_statement) previously raised OperationalError out of the blocking wait instead of | ||
| being recognized as already terminal -- see _wait_for_statement_stopped's docstring. | ||
|
|
||
| `SELECT 1/0` fails fast enough (confirmed live: well under a second) that execute() itself | ||
| raises with "submission failed" -- Cursor.execute() sets cursor.statement before that | ||
| raise (cursor.py:251-264), so the FAILED statement is still available to stop by name.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
... stopping already terminal state statements result in a no-op.
Closes #203. More details there in the issue.