Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
o-l-a-v opened this issue Apr 11, 2024 · 1 comment

Comments

@o-l-a-v
Copy link

o-l-a-v commented Apr 11, 2024

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • 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

@jpawlowski
Copy link

jpawlowski commented Jul 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants