Skip to content

Deleting a User that belongs to an org with 0 repositories may result in database error in mssql #34448

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

Closed
ChristopherHX opened this issue May 13, 2025 · 1 comment · Fixed by #34449
Labels
Milestone

Comments

@ChristopherHX
Copy link
Contributor

Description

user_service.DeleteUser(t.Context(), user, true) fails on mssql for userid 2 in testdata

Due to NumRepos being 0 for one org this user belongs to.
https://github.com/go-gitea/gitea/blob/7a097138deeb0289c1d52c942eb1b1dfe20d1cda/services/org/user.go#L67-L68

Not a problem on any other database

Gitea Version

1.24-rc0

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

1.39.5

Operating System

macOS

How are you running Gitea?

in test environment

// Test that the ephemeral runner is deleted when a user is deleted
func testEphemeralActionsRunnerDeletionByUser(t *testing.T) {
	defer tests.PrepareTestEnv(t)()

	_, err := actions_model.GetRunnerByID(t.Context(), 34350)
	assert.NoError(t, err)

	task := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 52})
	assert.Equal(t, actions_model.StatusRunning, task.Status)

	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})

	err = user_service.DeleteUser(t.Context(), user, true)
	assert.NoError(t, err)

	_, err = actions_model.GetRunnerByID(t.Context(), 34350)
	assert.ErrorIs(t, err, util.ErrNotExist)
}

Database

MSSQL

@ChristopherHX
Copy link
Contributor Author

The message is

        actions_runner_ephemeral_deletion_test.go:76: 
            	Error Trace:	/home/runner/work/gitea/gitea/tests/integration/actions_runner_ephemeral_deletion_test.go:76
            	Error:      	Received unexpected error:
            	            	unable to remove user user2[2] from org private_org35[35]. Error: GetUserRepositories [2]: mssql: The number of rows provided for a FETCH clause must be greater then zero.

@lunny lunny added this to the 1.24.0 milestone May 13, 2025
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue May 13, 2025
* mssql does not support fetching 0 repositories
  * remove paging by NumRepos that might be 0
* extend admin api test to purge user 2

Fixes go-gitea#34448

---------

Co-authored-by: wxiaoguang <[email protected]>
lunny pushed a commit that referenced this issue May 13, 2025
Backport #34449 by @ChristopherHX

* mssql does not support fetching 0 repositories
* remove paging by NumRepos that might be 0
* extend admin api test to purge user 2

Fixes #34448

Co-authored-by: ChristopherHX <[email protected]>
Co-authored-by: wxiaoguang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants