From 77dba1b5eafee3b2e828be553367ea1226ab9818 Mon Sep 17 00:00:00 2001 From: Jeff Li Date: Sat, 31 Jan 2026 11:24:43 +0800 Subject: [PATCH] repo: fix 500 error on watchers and stargazers pages using MSSQL (#6386) Co-authored-by: Joe Chen Co-authored-by: Claude --- CHANGELOG.md | 1 + internal/database/repo.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a88aa482a..c88584b86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ All notable changes to Gogs are documented in this file. ### Fixed +- 500 error on repository watchers and stargazers pages when using MSSQL. [#5482](https://github.com/gogs/gogs/issues/5482) - Submodules using `ssh://` protocol and a port number are not rendered correctly. [#4941](https://github.com/gogs/gogs/issues/4941) - Missing link to user profile on the first commit in commits history page. [#7404](https://github.com/gogs/gogs/issues/7404) - Unable to delete or display files with special characters in their names. [#7596](https://github.com/gogs/gogs/issues/7596) diff --git a/internal/database/repo.go b/internal/database/repo.go index ae8d7b946..77385c9d0 100644 --- a/internal/database/repo.go +++ b/internal/database/repo.go @@ -2408,7 +2408,7 @@ func GetWatchers(repoID int64) ([]*Watch, error) { func (r *Repository) GetWatchers(page int) ([]*User, error) { users := make([]*User, 0, ItemsPerPage) sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("watch.repo_id=?", r.ID) - if conf.UsePostgreSQL { + if conf.UsePostgreSQL || conf.UseMSSQL { sess = sess.Join("LEFT", "watch", `"user".id=watch.user_id`) } else { sess = sess.Join("LEFT", "watch", "user.id=watch.user_id") @@ -2508,7 +2508,7 @@ func IsStaring(userID, repoID int64) bool { func (r *Repository) GetStargazers(page int) ([]*User, error) { users := make([]*User, 0, ItemsPerPage) sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("star.repo_id=?", r.ID) - if conf.UsePostgreSQL { + if conf.UsePostgreSQL || conf.UseMSSQL { sess = sess.Join("LEFT", "star", `"user".id=star.uid`) } else { sess = sess.Join("LEFT", "star", "user.id=star.uid")