MethodsAndPractices / vsteam

PowerShell module for accessing Azure DevOps Services and Azure DevOps Server (formerly VSTS or TFS)
https://methodsandpractices.github.io/vsteam-docs/
MIT License
444 stars 155 forks source link

Get-VSTeamWiql with (resultset.Count modulus 200) == 1 throws ParameterBindingValidationException #392

Closed AlanMcBee closed 2 years ago

AlanMcBee commented 3 years ago

Steps to reproduce

Using:

# Change value of ID criteria as needed
$wiql = @'
SELECT
    [System.Id],
    [System.Title]
FROM workitems
WHERE
    [System.Id] = 5000
ORDER BY [System.Id]
'@

$workItem = Get-VSTeamWiql -Query $wiql -Expand

Expected behavior

$workItem populated with work item with ID of 5000

Actual behavior

ParameterBindingValidationException thrown:

Get-VSTeamWorkItem: C:\Program Files\WindowsPowerShell\Modules\VSTeam\7.2.0\vsteam.functions.ps1:5692
Line |
5692 |  …           Get-VSTeamWorkItem -Id $Ids[$beginRange..$endRange] -Fields …
     |                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot bind argument to parameter 'Id' because it is null.

Environment data

OS

Server

> Get-VSTeamAPIVersion

Billing                     : 5.1-preview.1
Build                       : 5.1
Core                        : 5.1
DistributedTask             : 6.0-preview
DistributedTaskReleased     : 5.1
ExtensionsManagement        : 6.0-preview
Git                         : 5.1
Graph                       : 6.0-preview
HierarchyQuery              : 5.1-preview
MemberEntitlementManagement : 6.0-preview
Packaging                   : 6.0-preview
Pipelines                   : 5.1-preview
Policy                      : 5.1
Processes                   : 6.0-preview
Release                     : 5.1
ServiceEndpoints            : 5.0-preview
TaskGroups                  : 6.0-preview
Tfvc                        : 5.1
VariableGroups              : 5.1-preview.1
Version                     : VSTS
> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
AlanMcBee commented 3 years ago

Just to make it clear that this isn't just a one-off:

I discovered this bug when executing a query that normally returns many items. It just happened to return exactly one this time.

SebastianSchuetze commented 3 years ago

@AlanMcBee I checked it yesterday and I can reproduce it. But not like you said with work items over 5000. This always comes up if you have an array of items where the count is a division of 200 and the remainder is 1.

This results in a case where the $beginRange = 0 and $endRange = 0, thus throwing the exception:

The line that can cause this is the following: https://github.com/MethodsAndPractices/vsteam/blob/e6cd718a9a41712b1d3384fc0d3354d80eeb82a4/Source/Public/Get-VSTeamWiql.ps1#L66

Unit tests need also be specified for this.

AlanMcBee commented 3 years ago

... But not like you said with work items over 5000.

That's not what I thought I was saying. That 5000 value was the ID of the single work item that should have been returned by the query. It could have been any ID. It would not have to be a query for a work item by its ID (like I used in the repro); it could also be, as you discovered and stated, any query that returns a count where the modulus 200 of the count is equal to 1 (which includes a query that has a count of 1). It has nothing to do with the value 5000.