Skip to content

Correct DbTransaction.SupportsSavepoints docs for Release and add tests for the default savepoint members - #137042

Open
alaricd wants to merge 3 commits into
dotnet:mainfrom
pengdows:dbtransaction-savepoints-docs-and-tests
Open

alaricd wants to merge 3 commits into
dotnet:mainfrom
pengdows:dbtransaction-savepoints-docs-and-tests

Conversation

@alaricd

@alaricd alaricd commented Nov 5, 2026 •

Copy link
Copy Markdown

Fixes #137040

Problem

The XML documentation on DbTransaction.SupportsSavepoints, which is also what learn.microsoft.com publishes, says that when it is false the methods SaveAsync, RollbackAsync and ReleaseAsync, "as well as their synchronous counterparts", are expected to throw NotSupportedException. The implementation does not do that for Release/ReleaseAsync:

public virtual void Save(string savepointName) => throw new NotSupportedException();
public virtual void Rollback(string savepointName) => throw new NotSupportedException();
public virtual void Release(string savepointName) { }

That is the shape approved in #33397, whose notes explain that a Release no-op by default "seems correct", since releasing has no user-visible behavior and should generally not throw. So the implementation is intentional and the sentence is what is out of step. A provider author, or anyone writing a conformance test from that sentence, will expect Release to throw, and every provider that does not override it appears to violate the contract.

Change

Documentation only, no behavior change:

  • SupportsSavepoints: Save/SaveAsync and Rollback(string)/RollbackAsync are the members expected to throw; a remark says Release/ReleaseAsync do nothing by default and do not throw when savepoints are unsupported.
  • Release and ReleaseAsync: a remark states the default behavior.

Tests

DbTransactionSavepointTests is new. It pins the default behavior of all six members so the documentation and the implementation cannot drift apart again: SupportsSavepoints defaults to false; Save and Rollback(string) throw NotSupportedException; Release does nothing; SaveAsync/RollbackAsync store the exception in the task rather than throwing; ReleaseAsync completes. It also covers the async members delegating to overridden synchronous ones, storing the exceptions those throw, and returning a canceled task for a canceled token without calling the synchronous method.

Because this is a documentation fix, the tests describe existing behavior and are expected to pass both before and after the doc change (they are in their own commit ahead of it).

I have not run these tests locally, and CI has not run them yet. Building dotnet/runtime's library tests needs a CoreCLR build, which my environment cannot do (no C++ toolchain). The PR is now ready for review, but the full build and test pipelines still need a maintainer to start them on this fork-based PR. I checked the code by reading it against the surrounding sources only; please run the pipelines, and until a green run exists, please treat the tests as unverified and tell me if anything fails to compile.

How this was found

Found by pengdows.AdoNetApiTest.conformance, an xUnit conformance suite for ADO.NET providers that checks the documented System.Data.Common contract. Its savepoint tests asserted that Release throws when savepoints are unsupported, built from that documentation sentence; they failed for System.Data.OleDb and for Sqlite. Reading the source and #33397 showed the suite, not the base class, was wrong, so the suite has been corrected and this PR corrects the documentation.

Pin what the savepoint members do when a provider overrides none of them: Save and
Rollback(string) and their asynchronous forms throw NotSupportedException (stored in
the task for the async ones), Release and ReleaseAsync do nothing. Also cover the
asynchronous members delegating to overridden synchronous ones, storing the
exceptions those throw, and returning a canceled task for a canceled token.
The summary said that SaveAsync, RollbackAsync and ReleaseAsync, and their synchronous
counterparts, are expected to throw NotSupportedException when SupportsSavepoints is
false. Release and ReleaseAsync do not: Release is a no-op by design, as the API
proposal for savepoints (dotnet#33397) describes. Say so on SupportsSavepoints, Release and
ReleaseAsync.

Fixes dotnet#137040
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 5, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @SamMonoRT, @dotnet/efteam
See info in area-owners.md if you want to be subscribed.

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

Approval should be deferred because the new System.Data.Common tests and documentation have not yet been built or executed, and CI validation remains pending.

No open issues 🎉

What changed in this PR

This PR corrects the DbTransaction XML documentation to match the existing default savepoint behavior, including the intentional no-op behavior of Release and ReleaseAsync. It also adds focused tests covering default savepoint members and asynchronous delegation behavior.

Changes:

  • Clarifies SupportsSavepoints, Release, and ReleaseAsync documentation.
  • Adds tests for default exceptions, no-op release behavior, cancellation, synchronous delegation, and task exception handling.
  • Includes the new savepoint test file in the System.Data.Common test project.
File Description
src/​libraries/​System.Data.Common/​tests/​System/​Data/​Common/​DbTransactionSavepointTests.cs Adds coverage for default and asynchronous savepoint behavior.
src/​libraries/​System.Data.Common/​tests/​System.Data.Common.Tests.csproj Includes the new savepoint test file in the test project.
src/​libraries/​System.Data.Common/​src/​System/​Data/​Common/​DbTransaction.cs Corrects savepoint API documentation without changing runtime behavior.

Review effort: Lite

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Data community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DbTransaction.SupportsSavepoints docs say Release/ReleaseAsync are expected to throw, but they are no-ops by design

2 participants