Skip to content

Stop throwing an error in an attempt to stop an already failed statement - #209

Draft
James Robinson (jlrobins) wants to merge 1 commit into
mainfrom
fix/203-unify-stop-statement-codepaths
Draft

Stop throwing an error in an attempt to stop an already failed statement #209
James Robinson (jlrobins) wants to merge 1 commit into
mainfrom
fix/203-unify-stop-statement-codepaths

Conversation

@jlrobins

Copy link
Copy Markdown
Contributor

... stopping already terminal state statements result in a no-op.

Closes #203. More details there in the issue.

…ent --- stopping already terminal state statements result in a no-op.
Copilot AI lite review requested due to automatic review settings September 4, 2026 20:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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_stopped so an already-terminal FAILED statement 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."""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stop_statement(): string-name path skips the terminal-phase short-circuit that the Statement-object path gets

2 participants