PowerShellGallery icon indicating copy to clipboard operation
PowerShellGallery copied to clipboard

API - Filter by version - `$filter=NormalizedVersion gt '9'` does not return any newer major versions

Open o-l-a-v opened this issue 1 year ago • 1 comments

Prerequisites

  • [X] Write a descriptive title.
  • [X] Make sure you are able to repro it on the latest version
  • [X] Search the existing issues.

Steps to reproduce

If you want to specify a minimum major version to return, you can do $filter=NormalizedVersion gt '9'.

If the module you're searching for has newer major versions than 9, say 10, the API won't return it.

Example request for Az, where I want the newest version returned, but at least major version 9:

More human friendly view:

# Filter on Version
[uri]::EscapeUriString(
    'https://www.powershellgallery.com/api/v2/Packages()?' +
    "`$filter=Id eq 'Az' and Version ge '9'&" +
    '$orderby=Version desc&' +
    '$top=1&' +
    '$select=NormalizedVersion,Version'
).Replace("'",'%27') | Set-Clipboard


# Filter on NormalizedVersion
[uri]::EscapeUriString(
    'https://www.powershellgallery.com/api/v2/Packages()?' +
    "`$filter=Id eq 'Az' and NormalizedVersion ge '9'&" +
    '$orderby=NormalizedVersion desc&' +
    '$top=1&' +
    '$select=NormalizedVersion,Version'
).Replace("'",'%27') | Set-Clipboard

Expected behavior

  • Example returns newest version, but at least version 9.
  • I expected (as of writing) v11.5.0.

Actual behavior

Example returns version v9.7.1; the newest v9 version before major jumped to v10 and beyond.

Error details

No response

Environment data

Not relevant, API

Version

Not relevant, API

Visuals

No response

o-l-a-v avatar Apr 11 '24 13:04 o-l-a-v

Sadly, this also affects the PSResourceGet module as well. It would generate URLs like this:

https://www.powershellgallery.com/api/v2/FindPackagesById()?id='Microsoft.Graph.Authentication'&$orderby=NormalizedVersion desc&$inlinecount=allpages&$skip=0&$filter=IsPrerelease eq false and Id eq 'Microsoft.Graph.Authentication' and NormalizedVersion ge '2.0.0' and NormalizedVersion lt '3.0.0'

which should send back a sorted list with the latest version of Microsoft.Graph.Authentication at position 0. However, the SemVer sorting is broken and so this is the result we get:

DEBUG: Request url is 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='Microsoft.Graph.Authentication'&$orderby=NormalizedVersion desc&$inlinecount=allpages&$skip=0&$filter=IsPrerelease eq false and Id eq 'Microsoft.Graph.Authentication' and NormalizedVersion ge '2.0.0' and NormalizedVersion lt '3.0.0''
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.9.1'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Package 'Microsoft.Graph.Authentication' was previously discovered and returned

DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.9.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.8.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.6.1'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.5.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.4.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.3.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.20.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.2.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.19.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.18.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.17.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.16.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.15.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.14.1'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.14.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.13.1'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.13.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.12.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.11.1'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.11.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.10.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.1.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
DEBUG: Found package 'Microsoft.Graph.Authentication' version '2.0.0'
DEBUG: Package 'Microsoft.Graph.Authentication' returned from server
Name                           Version Prerelease Repository Description
----                           ------- ---------- ---------- -----------
Microsoft.Graph.Authentication 2.9.1              PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.9.0              PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.8.0              PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.6.1              PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.5.0              PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.4.0              PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.3.0              PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.20.0             PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.2.0              PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.19.0             PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.18.0             PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.17.0             PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.16.0             PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.15.0             PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.14.1             PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.14.0             PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.13.1             PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.13.0             PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.12.0             PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.11.1             PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.11.0             PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.10.0             PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.1.0              PSGallery  Microsoft Graph PowerShell Authentication Module.
Microsoft.Graph.Authentication 2.0.0              PSGallery  Microsoft Graph PowerShell Authentication Module.

One can clearly see that the minor version sorting is not correct, assuming the version string is not interpreted as [System.Version] in SemVer format as it should be. That means for modules with minor version numbers above 9, the sorting is going to be broken for them.

jpawlowski avatar Jul 11 '24 17:07 jpawlowski