Skip to content

fix: honor configured query retries and stop retry-event crash#730

Draft
joshmarkovic wants to merge 1 commit into
dbt-msft:masterfrom
joshmarkovic:fix/query-retry-loop
Draft

fix: honor configured query retries and stop retry-event crash#730
joshmarkovic wants to merge 1 commit into
dbt-msft:masterfrom
joshmarkovic:fix/query-retry-loop

Conversation

@joshmarkovic

Copy link
Copy Markdown
Contributor

What

Fixes two defects in the query-level retry path in SQLServerConnectionManager.add_query.

1. The retry-debug event crashed instead of retrying. On a retryable error, the code fired AdapterEventDebug(message=...), but the event field is base_msg. Constructing the event with message= raises a protobuf ParseError, so the first retryable error crashed at event construction rather than triggering a retry. dbt-core's base add_query uses base_msg=; this matches it.

2. Configured retry counts of 1-3 were silently ignored. The retry limit was computed as credentials.retries if credentials.retries > 3 else retry_limit, where retry_limit is a hardcoded 2. So any configured retries value of 1, 2, or 3 was discarded in favor of 2, meaning even the default retries: 3 only attempted a query twice. This now passes credentials.retries directly, mirroring open(), which already drives connection retries off credentials.retries.

Behavior change

With these fixes, query retries actually function (previously the first retryable error raised a ParseError), and the configured retries value is honored. With the default retries: 3, a retryable query is now attempted up to 3 times rather than 2.

Tests

Adds unit tests for add_query's retry path:

  • retry until success on a retryable error,
  • the retries: 3 regression (attempts the configured number of times),
  • no retry when retries: 1,
  • non-retryable errors are not retried.

Verification

  • Full unit suite: 272 passed.
  • ruff, black (line-length 99, py310), and mypy all clean on the changed files.
  • dbt/adapters/sqlserver/sqlserver_connections.py was unchanged between the base this work started from and current master, so the change applies cleanly with no overlap against recent work.

The query-level retry in SQLServerConnectionManager.add_query had two
defects:

- A `credentials.retries > 3` guard silently ignored configured retry
  counts of 1-3 and fell back to a hardcoded limit of 2, so even the
  default `retries: 3` only attempted a query twice. Use
  `credentials.retries` directly, matching how open() drives connection
  retries.
- The retry-debug event was built as `AdapterEventDebug(message=...)`,
  but the event field is `base_msg`; constructing it raised a protobuf
  ParseError on the first retryable error, so retries crashed instead of
  retrying. Use `base_msg=` as dbt-core's base add_query does.

Add unit tests covering retry-until-success, the retries=3 regression,
no-retry at retries=1, and non-retryable errors not being retried.
@joshmarkovic joshmarkovic marked this pull request as draft June 29, 2026 20:21
@axellpadilla axellpadilla added this to the v1.10.1 milestone Jun 30, 2026
@axellpadilla

Copy link
Copy Markdown
Collaborator

Just flagged this for final release 1.10.1

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.

2 participants