Find-DbaAgentJob - Only the last condition filter counts when several are given

オープン
#10,853 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
半日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
powershell
領域
databases

調査の方向性

Read the Find-DbaAgentJob command and list every place its condition filters reassign $output from $jobs instead of narrowing it; the help examples for -IsDisabled -IsNoEmailNotification -IsNotScheduled and the Get-DbaRegServer | Find-DbaAgentJob -Disabled -IsNotScheduled example need rewriting to match whichever semantics is chosen. Reproduce with the two-job lab from the issue (A disabled with a schedule, B enabled without one) and check the extra claim that [boolean]$LastUsed.ToString() never blocks a filterless call. Done means a maintainer decision on AND vs OR is recorded, all condition filters compose accordingly, help text matches, and tests cover two conditions together and with -JobName.

索引モデルが issue の本文から書いたものです。

説明

bugs life Chrissy needed

What happens

Find-DbaAgentJob has seven condition filters: -Category, -IsFailed, -LastUsed, -IsDisabled, -IsNotScheduled, -IsNoEmailNotification and -Owner. Each one does $output = $jobs | Where-Object .... That starts again from all jobs (or from the jobs that -JobName, -StepName or -Pattern selected) and throws away what the filters before it found. So when several are given, only the last one in the code counts, whatever order the call uses. -ExcludeJobName and -Since filter $output and do combine.

Lab, development 895132336, SQL Server 2019, two jobs: A is disabled and has a schedule, B is enabled and has none.

Call Result
-JobName A, B -IsDisabled A
-JobName A, B -IsNotScheduled B
-JobName A, B -IsDisabled -IsNotScheduled B
-IsNotScheduled -IsDisabled -JobName A, B B

With AND, the combined call would return nothing; with OR, it would return both jobs.

Two help examples promise OR:

  • -IsDisabled -IsNoEmailNotification -IsNotScheduled: "either disabled, have no email notification or don't have a schedule". It returns only the jobs without e-mail notification, because -IsNoEmailNotification comes last in the code.
  • Get-DbaRegServer ... | Find-DbaAgentJob -Disabled -IsNotScheduled: "either been disabled or have no schedule". It returns only the jobs without a schedule.

#6274 fixed -JobName combined with one condition filter in 2020 (the filters start from the jobs -JobName selected), but not two condition filters together.

The question

A fix changes the result for every caller who combines these switches today, in one of two directions:

  • AND: a job has to match every given filter. That is what several filter parameters usually mean in PowerShell, and what #6274 asked for with -JobName. -IsDisabled -IsNotScheduled would then mean "disabled and without a schedule".
  • OR: a job that matches any given filter is returned, as the two examples promise. This suits an audit ("show me everything that looks wrong"), but -JobName keeps its AND role while the condition filters get OR, which is harder to explain.

Which one should it be? I would go with AND and rewrite the two examples. Once that is decided, the fix is a few lines plus tests.

Found on the way

begin refuses a call without any search term ("At least one search term must be specified"). But one of the terms in that check is [boolean]$LastUsed.ToString(), and that is always $true, because "0" is a non-empty string. So the check never fires: Find-DbaAgentJob -SqlInstance x with no filter at all returns every job, without a warning (lab: 3 jobs, no warning). Fixing the check would break callers who rely on this, so it might be better to document "without a filter it returns all jobs" than to make the check work. Same question: which way?

Found while fixing #10833 in #10848.


This text was created by Claude and reviewed by Andreas Jordan.

主要言語
PowerShell
スター
2.9k
フォーク
869
平均マージ
2日 4時間
マージ済み PR(30日)
38

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dataplat/dbatools のほかの issue

dataplat/dbatools の issue をすべて見る

似ている issue

Databases の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。