Repository navigation
Fix Database.Owner not reflecting SetOwner() until Refresh() - #231
Open
Andreas Jordan (andreasjordan) wants to merge 2 commits into
Open
Andreas Jordan (andreasjordan) wants to merge 2 commits into
Andreas Jordan (andreasjordan) wants to merge 2 commits into
Conversation
This was referenced Aug 28, 2026
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The tests do not verify the server-canonical casing behavior central to the implementation.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Fixes stale Database.Owner values after SetOwner() by lazily retrieving the canonical server value.
Changes:
- Invalidates the cached owner after successful execution.
- Adds immediate-owner functional assertions.
- Documents the externally visible fix.
| File | Description |
|---|---|
DatabaseBase.cs |
Invalidates the owner cache. |
Database_SmoTestSuite.cs |
Tests owner access before refresh. |
CHANGELOG.md |
Records the behavior fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
SetOwnerImpl only executed the ALTER AUTHORIZATION statement without touching the property bag, so Database.Owner kept returning the previous owner until Refresh() was called (issue microsoft#40). Instead of storing the caller-provided login name (which may differ from the canonical name the server stores, e.g. by casing on a case-insensitive server), mark the Owner property as not retrieved and the property bag as lazy - the same pattern CleanObject uses for the default language properties - so the next read of Owner fetches the canonical value from the server. The existing Database_CanChangeOwner tests worked around the bug by calling Refresh() before asserting; they now also assert the value before Refresh(). Fixes microsoft#40 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…nt casing The regression assertions only passed the login's stored spelling, so an implementation that copied the caller-provided name into the property bag would pass them as well. On a case-insensitive server, Database_CanChangeOwner now also calls SetOwner with the upper-cased login name and asserts that Owner returns the name as stored on the server, without Refresh(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Andreas Jordan (andreasjordan)
force-pushed
the
fix-database-setowner-stale-owner
branch
from
October 9, 2026 16:14
cc401f2 to
46c5ded
Compare
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.

Fixes #40.
SetOwnerImplonly executed the ALTER AUTHORIZATION batch without touching the property bag, soDatabase.Ownerkept returning the previous owner untilRefresh()was called.Rather than writing the caller-provided login name into the property (it may differ from what the server stores, e.g. by casing on a case-insensitive server), the fix invalidates the cached
Ownerproperty and marks the property bag lazy - the same patternCleanObjectuses for the default language properties - so the next read ofOwnerfetches the canonical value from the server. The invalidation is skipped in capture mode since nothing was executed.The existing
Database_CanChangeOwnertests worked around the bug by callingRefresh()before asserting; they now also assert the value beforeRefresh(). On a case-insensitive server,Database_CanChangeOwneralso callsSetOwnerwith the upper-cased login name and asserts that the server's spelling is returned.Verified against SQL Server 2019: after
SetOwner("sa"),OwnerreturnssawithoutRefresh(); afterSetOwnerwith a differently-cased Windows login,Ownerreturns the server's canonical casing.This fix was created by Claude and reviewed by Andreas Jordan.