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

NuGet: Order of pushing packages breaks version grouping #21434

Closed
fitithw opened this issue Oct 13, 2022 · 2 comments · Fixed by #21442
Closed

NuGet: Order of pushing packages breaks version grouping #21434

fitithw opened this issue Oct 13, 2022 · 2 comments · Fixed by #21442

Comments

@fitithw
Copy link
Contributor

fitithw commented Oct 13, 2022

Description

Very weird bug, no idea what causes it besides the push order, package names don't matter, nor the push times.
You can skip steps 2-5 if you just want to see the bugged version.

  1. Create the packages:
$API_KEY="xxx"
$OWNER="xxx"
$GITEA_HOST="https://try.gitea.io"
$SOURCE="$GITEA_HOST/api/packages/$OWNER/nuget/index.json"
$HEADERS=@{Authorization = "bearer $API_KEY"}

dotnet new classlib -n TestGiteaNuGet
msbuild .\TestGiteaNuGet\TestGiteaNuGet.csproj /t:pack /p:version=1.0.1 /p:includesymbols=true /p:symbolpackageformat=snupkg
msbuild .\TestGiteaNuGet\TestGiteaNuGet.csproj /t:pack /p:version=1.0.2 /p:includesymbols=true /p:symbolpackageformat=snupkg
msbuild .\TestGiteaNuGet\TestGiteaNuGet.csproj /t:pack /p:version=1.0.3 /p:includesymbols=true /p:symbolpackageformat=snupkg

dotnet new classlib -n TestGiteaNuGet.UI
msbuild .\TestGiteaNuGet.UI\TestGiteaNuGet.UI.csproj /t:pack /p:version=1.0.1 /p:includesymbols=true /p:symbolpackageformat=snupkg
msbuild .\TestGiteaNuGet.UI\TestGiteaNuGet.UI.csproj /t:pack /p:version=1.0.2 /p:includesymbols=true /p:symbolpackageformat=snupkg
msbuild .\TestGiteaNuGet.UI\TestGiteaNuGet.UI.csproj /t:pack /p:version=1.0.3 /p:includesymbols=true /p:symbolpackageformat=snupkg
  1. Push the packages in order of package name and query the package server:
dotnet nuget push --source $SOURCE .\TestGiteaNuGet\bin\Debug\TestGiteaNuGet.1.0.1.nupkg --api-key $API_KEY
dotnet nuget push --source $SOURCE .\TestGiteaNuGet\bin\Debug\TestGiteaNuGet.1.0.2.nupkg --api-key $API_KEY
dotnet nuget push --source $SOURCE .\TestGiteaNuGet\bin\Debug\TestGiteaNuGet.1.0.3.nupkg --api-key $API_KEY
dotnet nuget push --source $SOURCE .\TestGiteaNuGet.UI\bin\Debug\TestGiteaNuGet.UI.1.0.1.nupkg --api-key $API_KEY
dotnet nuget push --source $SOURCE .\TestGiteaNuGet.UI\bin\Debug\TestGiteaNuGet.UI.1.0.2.nupkg --api-key $API_KEY
dotnet nuget push --source $SOURCE .\TestGiteaNuGet.UI\bin\Debug\TestGiteaNuGet.UI.1.0.3.nupkg --api-key $API_KEY

(Invoke-WebRequest -Uri $GITEA_HOST/api/packages/$OWNER/nuget/query?q=TestGiteaNuGet -Headers $HEADERS).Content

The results of NuGet query are correct:

{
    "totalHits": 6,
    "data": [
        {
            "id": "TestGiteaNuGet.UI",
            "version": "1.0.3",
            "versions": [
                {
                    "@id": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet.UI/1.0.3.json",
                    "version": "1.0.3",
                    "downloads": 0
                },
                {
                    "@id": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet.UI/1.0.2.json",
                    "version": "1.0.2",
                    "downloads": 0
                },
                {
                    "@id": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet.UI/1.0.1.json",
                    "version": "1.0.1",
                    "downloads": 0
                }
            ],
            "description": "Package Description",
            "authors": "TestGiteaNuGet.UI",
            "projectURL": "",
            "registration": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet.UI/index.json"
        },
        {
            "id": "TestGiteaNuGet",
            "version": "1.0.3",
            "versions": [
                {
                    "@id": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet/1.0.3.json",
                    "version": "1.0.3",
                    "downloads": 0
                },
                {
                    "@id": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet/1.0.2.json",
                    "version": "1.0.2",
                    "downloads": 0
                },
                {
                    "@id": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet/1.0.1.json",
                    "version": "1.0.1",
                    "downloads": 0
                }
            ],
            "description": "Package Description",
            "authors": "TestGiteaNuGet",
            "projectURL": "",
            "registration": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet/index.json"
        }
    ]
}
  1. Now delete the packages from Gitea, either through UI or API:
Invoke-WebRequest -Uri $GITEA_HOST/api/v1/packages/$OWNER/nuget/testgiteanuget.ui/1.0.3 -Method DELETE -Headers $HEADERS
Invoke-WebRequest -Uri $GITEA_HOST/api/v1/packages/$OWNER/nuget/testgiteanuget.ui/1.0.2 -Method DELETE -Headers $HEADERS
Invoke-WebRequest -Uri $GITEA_HOST/api/v1/packages/$OWNER/nuget/testgiteanuget.ui/1.0.1 -Method DELETE -Headers $HEADERS
Invoke-WebRequest -Uri $GITEA_HOST/api/v1/packages/$OWNER/nuget/testgiteanuget/1.0.3 -Method DELETE -Headers $HEADERS
Invoke-WebRequest -Uri $GITEA_HOST/api/v1/packages/$OWNER/nuget/testgiteanuget/1.0.2 -Method DELETE -Headers $HEADERS
Invoke-WebRequest -Uri $GITEA_HOST/api/v1/packages/$OWNER/nuget/testgiteanuget/1.0.1 -Method DELETE -Headers $HEADERS
  1. Optional (local instance): clear the package SQL table as the methods above do not, just to be sure (it works either way):
delete from package where lower_name in ('testgiteanuget', 'testgiteanuget.ui')
  1. Push the packages in order of package version and query the package server:
dotnet nuget push --source $SOURCE .\TestGiteaNuGet\bin\Debug\TestGiteaNuGet.1.0.1.nupkg --api-key $API_KEY
dotnet nuget push --source $SOURCE .\TestGiteaNuGet.UI\bin\Debug\TestGiteaNuGet.UI.1.0.1.nupkg --api-key $API_KEY
dotnet nuget push --source $SOURCE .\TestGiteaNuGet\bin\Debug\TestGiteaNuGet.1.0.2.nupkg --api-key $API_KEY
dotnet nuget push --source $SOURCE .\TestGiteaNuGet.UI\bin\Debug\TestGiteaNuGet.UI.1.0.2.nupkg --api-key $API_KEY
dotnet nuget push --source $SOURCE .\TestGiteaNuGet\bin\Debug\TestGiteaNuGet.1.0.3.nupkg --api-key $API_KEY
dotnet nuget push --source $SOURCE .\TestGiteaNuGet.UI\bin\Debug\TestGiteaNuGet.UI.1.0.3.nupkg --api-key $API_KEY

(Invoke-WebRequest -Uri $GITEA_HOST/api/packages/$OWNER/nuget/query?q=TestGiteaNuGet -Headers $HEADERS).Content

The results of NuGet query are incorrect, every version is an individual package:

{
    "totalHits": 6,
    "data": [
        {
            "id": "TestGiteaNuGet.UI",
            "version": "1.0.3",
            "versions": [
                {
                    "@id": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet.UI/1.0.3.json",
                    "version": "1.0.3",
                    "downloads": 0
                }
            ],
            "description": "Package Description",
            "authors": "TestGiteaNuGet.UI",
            "projectURL": "",
            "registration": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet.UI/index.json"
        },
        {
            "id": "TestGiteaNuGet",
            "version": "1.0.3",
            "versions": [
                {
                    "@id": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet/1.0.3.json",
                    "version": "1.0.3",
                    "downloads": 0
                }
            ],
            "description": "Package Description",
            "authors": "TestGiteaNuGet",
            "projectURL": "",
            "registration": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet/index.json"
        },
        {
            "id": "TestGiteaNuGet.UI",
            "version": "1.0.2",
            "versions": [
                {
                    "@id": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet.UI/1.0.2.json",
                    "version": "1.0.2",
                    "downloads": 0
                }
            ],
            "description": "Package Description",
            "authors": "TestGiteaNuGet.UI",
            "projectURL": "",
            "registration": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet.UI/index.json"
        },
        {
            "id": "TestGiteaNuGet",
            "version": "1.0.2",
            "versions": [
                {
                    "@id": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet/1.0.2.json",
                    "version": "1.0.2",
                    "downloads": 0
                }
            ],
            "description": "Package Description",
            "authors": "TestGiteaNuGet",
            "projectURL": "",
            "registration": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet/index.json"
        },
        {
            "id": "TestGiteaNuGet.UI",
            "version": "1.0.1",
            "versions": [
                {
                    "@id": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet.UI/1.0.1.json",
                    "version": "1.0.1",
                    "downloads": 0
                }
            ],
            "description": "Package Description",
            "authors": "TestGiteaNuGet.UI",
            "projectURL": "",
            "registration": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet.UI/index.json"
        },
        {
            "id": "TestGiteaNuGet",
            "version": "1.0.1",
            "versions": [
                {
                    "@id": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet/1.0.1.json",
                    "version": "1.0.1",
                    "downloads": 0
                }
            ],
            "description": "Package Description",
            "authors": "TestGiteaNuGet",
            "projectURL": "",
            "registration": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet/index.json"
        }
    ]
}

Here's how it looks on Visual Studio 2022 Package Manager:
vs_nuget_bug

  1. Now let's delete one of the packages and see if it "fixed" the other one:
Invoke-WebRequest -Uri $GITEA_HOST/api/v1/packages/$OWNER/nuget/testgiteanuget.ui/1.0.3 -Method DELETE -Headers $HEADERS
Invoke-WebRequest -Uri $GITEA_HOST/api/v1/packages/$OWNER/nuget/testgiteanuget.ui/1.0.2 -Method DELETE -Headers $HEADERS
Invoke-WebRequest -Uri $GITEA_HOST/api/v1/packages/$OWNER/nuget/testgiteanuget.ui/1.0.1 -Method DELETE -Headers $HEADERS

(Invoke-WebRequest -Uri $GITEA_HOST/api/packages/$OWNER/nuget/query?q=TestGiteaNuGet -Headers $HEADERS).Content

The other one is back to normal:

{
    "totalHits": 3,
    "data": [
        {
            "id": "TestGiteaNuGet",
            "version": "1.0.3",
            "versions": [
                {
                    "@id": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet/1.0.3.json",
                    "version": "1.0.3",
                    "downloads": 0
                },
                {
                    "@id": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet/1.0.2.json",
                    "version": "1.0.2",
                    "downloads": 0
                },
                {
                    "@id": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet/1.0.1.json",
                    "version": "1.0.1",
                    "downloads": 0
                }
            ],
            "description": "Package Description",
            "authors": "TestGiteaNuGet",
            "projectURL": "",
            "registration": "https://try.gitea.io/api/packages/fitithw/nuget/registration/TestGiteaNuGet/index.json"
        }
    ]
}

Gitea Version

1.17.2

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

Windows Server 2019 Standard

How are you running Gitea?

Windows service from downloaded exe, but the bug can be reproduced on try.gitea.io.

Database

MSSQL

@KN4CK3R
Copy link
Member

KN4CK3R commented Oct 13, 2022

Could you please dump the package and package_version tables for me when receiving the wrong result?

Found the error, will fix it soon.

@KN4CK3R
Copy link
Member

KN4CK3R commented Oct 13, 2022

Added a fix in #21442. Thank you for the detailed analysis 👍

wxiaoguang added a commit that referenced this issue Oct 16, 2022
Fixes #21434

Added tests to enforce this behaviour.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
KN4CK3R added a commit to KN4CK3R/gitea that referenced this issue Oct 16, 2022
Fixes go-gitea#21434

Added tests to enforce this behaviour.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants