Repository navigation
Tests - Report Query() calls whose value goes to the output - #10798
Open
andreasjordan wants to merge 2 commits into
Open
andreasjordan wants to merge 2 commits into
andreasjordan wants to merge 2 commits into
Conversation
Query() returns $null for a batch without a result set, and a call whose value nothing takes writes that $null into the output of the command (#10794). #10791, #10795, #10796 and #10797 fix the 86 such sites on development; this check keeps new ones out. Get-DbaBareQueryFinding follows the value of every .Query(...) call up the tree, the way PowerShell passes it on, and the "command structure" Describe reports every call whose value reaches its function. The 19 calls that return the rows of a SELECT as their output are listed with the exact number of sites, like the rule 1 exceptions, which share the comparison with them now. Fixtures in the analyzer Describe cover what passes the value on and what takes it. tests/CLAUDE.md no longer recommends counting with $results.Status.Count, which skips a $null, and documents the check. Until the four PRs are merged, the new test fails on purpose, with the 86 sites they fix. (do dbatools) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
andreasjordan
marked this pull request as ready for review
October 23, 2026 15:21
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.
Part of #10794: the check that keeps new bare
Query()calls out, now that the fixes are in. #10791, #10795, #10796 and #10797 are merged, and development is merged into this branch (1431760). The scan finds exactly the 19 listed sites, anddbatools.Tests.ps1passes in the lab (87 passed, 6 skipped, 0 failed, Windows PowerShell 5.1).What it checks
The
Query()script methods of the SMO Server and Database objects return$nullfor a batch without a result set, and a call whose value nothing takes writes that$nullinto the output of the command. The new test in the "command structure" Describe (Compliance tag, no SQL Server needed) reports every.Query(...)call inpublic/andprivate/functions/whose value reaches its function.Get-DbaBareQueryFindingintests/dbatools.CommandStructure.ps1follows the value up the syntax tree, the way PowerShell passes it on:$( ),@( ),( ), array literals$null| Out-Null,| Select-Object)return,throw, an argument, an operand, the object of a member&or.that runs itSo
$items | ForEach-Object { $server.Query("DROP ...") }is reported, while$rows = if ($x) { $server.Query($sql) }andforeach ($row in @($db.Query($sql)))are not. The last one is the false positive the scan in the issue had (Get-EncryptedObjectImageValue).The exceptions
19 calls return the rows of a SELECT as their output on purpose (Get-DbaConnection, Get-DbaPermission, Read-DbaTransactionLog, the helpers of Get-DbaDatabase, ...). They are listed next to the rule 1 exceptions with file, function, exact number of sites and reason, and the comparison is shared: a new site in a listed function, or a listed one that is gone, fails the check until the entry is updated. The rule 1 messages are unchanged.
Fixtures in the "command structure analyzer" Describe cover both columns of the table above, a helper function inside a command, and the method name in any spelling.
tests/CLAUDE.md
"Array Operations" recommended
$results.Status.Countfor counting. That skips a$nullin the output, and it is how these$nullwent unnoticed: it now says to count the output itself with@($results).Count, or to assert that it holds no$null. The section on the structural checks describes the new one.Tests
PowerShell 5.1 and 7.6, the two "command structure" Describes:
Merge order
After #10791, #10795, #10796 and #10797. If a bare
Query()comes into development before that, this check reports it as well.🤖 Generated with Claude Code