Skip to content

Report command failures while reading results - #39405

Merged
AndriySvyryd merged 4 commits into
dotnet:mainfrom
Shivansh-Gaur2:issue-35229
Oct 30, 2026
Merged

AndriySvyryd merged 4 commits into
dotnet:mainfrom
Shivansh-Gaur2:issue-35229

Conversation

@Shivansh-Gaur2

Copy link
Copy Markdown
Contributor

Fixes #35229

A provider can raise a database error from DbDataReader.Read or NextResult after ExecuteReader succeeds. These errors currently bypass CommandFailed, affecting both query enumeration and batched SaveChanges.

This change reports provider reader-advancement failures through the existing command failure callbacks, including sync, async, and buffered consumption. Cancellations use CommandCanceled. EF row materialization exceptions remain on the query-iteration path, and QueryIterationFailed is preserved.

Reporting accounts for ordinary ILogger logging, event-specific diagnostic listeners, and command interceptors independently. No supported public API is added.

Validation

  • Added 50 relational regression cases covering streaming and buffering, reads and result advancement, failures and cancellation, logging/diagnostics/interceptors, materialization exclusion, and reader disposal.
  • Before the reporting-gate fix: 24 of those cases failed because events were missing; after the fix, all 50 pass.
  • Relational command/reader suites: 157 passed, 0 failed.
  • SQLite command-interception suite: 300 passed, 0 failed, including the actual abs(long.MinValue) reproduction in sync/async and streaming/buffered modes.
  • Relational project build: 0 warnings and 0 errors.
  • git diff --check: passed.

Checklist

  • Read .github/CONTRIBUTING.md.
  • Added regression tests and used the documented commit format.
  • Local build and focused test suites pass.
  • EF Core team feedback on the callback behavior change.
  • Contributor License Agreement.
  • GitHub automated build checks.

- Notify command interceptors about provider reader failures.

- Cover query reads, cancellation, and SaveChanges result advancement.

Fixes dotnet#35229
- Include failure and cancellation logging consumers when enabling reader reporting.
- Cover buffered reads, result advancement, materialization boundaries, and SQLite overflow.
@Shivansh-Gaur2

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

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.

🔵 Needs a closer look

Human validation is warranted because the cross-cutting diagnostics changes affect async reader lifetimes, callback reentrancy, provider-specific behavior, and extensibility cases not covered by the focused tests.

No open issues 🎉

What changed in this PR

This pull request reports provider failures from DbDataReader.Read and NextResult through existing command failure or cancellation callbacks across query enumeration, buffering, and batched SaveChanges.

Changes:

  • Added centralized synchronous and asynchronous reader-error reporting.
  • Routed streaming, buffered, grouped-query, and modification-batch reader advancement through reporting-aware paths.
  • Added regression coverage for failures, cancellation, diagnostics, interceptors, disposal, and materialization behavior.
File Summary
test/​EFCore.Sqlite.FunctionalTests/​CommandInterceptionSqliteTest.cs Adds SQLite overflow and batched SaveChanges regression coverage.
test/​EFCore.Relational.Tests/​Storage/​RelationalCommandTest.cs Covers reader failures, cancellation, buffering, diagnostics, logging, interception, and disposal.
test/​EFCore.Relational.Specification.Tests/​CommandInterceptionTestBase.cs Adds shared query read-failure, cancellation, and materialization tests.
src/​EFCore.Relational/​Update/​AffectedCountModificationCommandBatch.cs Routes batched result advancement through reporting-aware methods. The new synchronous and asynchronous paths bypass the existing virtual DbDataReader extension point, potentially skipping provider-decorated readers.
src/​EFCore.Relational/​Storage/​RelationalDataReader.cs Adds synchronous and asynchronous reader-advancement reporting. The asynchronous helper can dereference cleared reporting state after disposal while an operation is pending, potentially masking the provider exception with a NullReferenceException.
src/​EFCore.Relational/​Storage/​RelationalCommand.cs Creates and configures command-error reporting for reader execution.
src/​EFCore.Relational/​Storage/​Internal/​RelationalCommandErrorReporter.cs Centralizes command failure and cancellation callback dispatch.
src/​EFCore.Relational/​Query/​RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.ClientMethods.cs Routes split-query reader advancement through reporting-aware methods.
src/​EFCore.Relational/​Query/​Internal/​GroupBySplitQueryingEnumerable.cs Uses reporting-aware reader advancement for grouped split queries.
src/​EFCore.Relational/​Query/​Internal/​GroupBySingleQueryingEnumerable.cs Uses reporting-aware reader advancement for grouped single queries.
src/​EFCore.Relational/​Query/​Internal/​BufferedDataReader.cs Reports provider failures encountered while buffering rows and advancing result sets.
src/​EFCore.Relational/​Diagnostics/​IDbCommandInterceptor.cs Documents callbacks for reader-consumption failures and cancellation.

Review effort: Lite

@AndriySvyryd

Copy link
Copy Markdown
Member

Some tests in NonSharedModelUpdatesSqlServerTest and IncompleteMappingInheritanceQuerySqlServerTest suites are failing. You need to exclude the errors from the SQL logger used in tests.

@Shivansh-Gaur2

Shivansh-Gaur2 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Update for @AndriySvyryd: fixed in commit d3abe0d. TestSqlLoggerFactory excludes CommandError events from SQL baselines and parameter history while retaining failed SQL in FailedSqlStatements for diagnostics. Locally, the full affected suites pass: NonSharedModelUpdatesSqlServerTest 23/23, IncompleteMappingInheritanceQuerySqlServerTest 98 passed and 4 skipped, and DataAnnotationSqlServerTest 102/102. The Build and Agent Harness Coverage workflows currently show action_required, so GitHub CI has not reported test results.

@AndriySvyryd

Copy link
Copy Markdown
Member

@Shivansh-Gaur2 Looks like the SQL logger now captures less than expected. Tests in PrimitiveCollectionsQuerySqliteTest, TPTGearsOfWarQuerySqliteTest and JsonQueryJsonTypeSqlServerTest are failing

@ShivanshGaur-Pathlock

ShivanshGaur-Pathlock commented Oct 29, 2026 •

Copy link
Copy Markdown

@AndriySvyryd, thanks for catching that. I fixed it in a63428a. Failed SQL stays in the logger history; the baseline comparison now skips only unexpected errors. I ran the SQLite functional suite and the affected SQL Server tests locally, and they passed. I couldn't run the SQL Server 2025-only migration test on my SQL Server 2019 instance. The CI test workflows are still waiting for approval.

@AndriySvyryd AndriySvyryd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution!

@AndriySvyryd
AndriySvyryd merged commit 6990229 into dotnet:main Oct 30, 2026
18 of 19 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IDbCommandInterceptor.CommandFailed does not capture all command exceptions

4 participants