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
500 error when viewing organization with PostgreSQL #2727
Comments
i haven't seen this with sqlite3 or at try.gogs.io, so it must be a PostgreSQL issue. what are the user names and organization names, any special characters? |
Hi. Thanks for the response. The user and organization names are "david" and "Readmore" respectively. No special characters. Judging by the error this is a string interpolation issue - postgres is getting "1,2" where it's expecting an integer. |
my suspicion is that the IDs in the tables are fine, but it might be the access operation (with go-xorm) that's causing the error for PostgreSQL. a text dump of the SQL table might help (e.g. for sqlite3 that's in gogs/data/gogs.db), or uploading the database file itself, somewhere. |
I dumped the database. I only modified email addresses and removed password hashes. Sorry. |
thanks, i don't see anything wrong on a quick glance, so it could be one of the go-xorm abstracted operations for PostgreSQL breaking somehow: TMK, MySQL seems to be the most stable choice ATM. |
Hi, I just pushed a fix to |
here is download link for the binary of the current
might be a good idea to start from a clean DB, also make sure you backup the original |
@neolit123 thanks for the binary! |
Hi @neolit123 - Thanks for the binary. I get an error when using it, though:
OK - just build from source on the |
@johnnylee, i was considering including the make a backup of the file and copy paste the version of the new binary (e.g. from the zip name) in there. |
i assume you started with a clean DB, recreating the user and organization? |
I started again with a clean DB, and I have the same problem, but I observed something along the way that might be useful. The organization page was working fine until I added a team with two members. When the team had one member I could view the page, but when it had two members it didn't work. |
hello and thanks for the further feedback. if the error is somehow different make sure you post it here. |
Thanks for the comments, but my question is: have you tested latest |
Hi Unknwon - I built and ran the |
|
I'm sorry - The report that I made above (7 hours ago) refers to the The error message hasn't changed. |
|
I apologize. The error hasn't changed since the first message in the thread. I get a 500 error when I attempt to view the organization's page - that is, I click on the organization name. See the original description above for the log message. When trying to reproduce the bug (using the |
Thanks, I'll try to locate this problem. |
I just updated to build 0.8.49.0229 and experience at least a related problem. Whenever I try to access the Dashboard or the team page, I get "500" in the browser. The error in the log is different, however:
I'm using PostgreSQL on Ubuntu Server 14.04 (Linaro/ARM). |
Same problem here, I am using MariaSQL:
|
Looks like I have to install PostreSQL... |
Whoever encounters |
Please test again with |
EDIT #1: Sorry, I was still on the develop branch. I'm trying now with EDIT #2: The story is the same on the I updated gogs and xorm but I'm still getting the identical error:
|
@johnnylee please dump the |
@xuanduc987 how do you know this line of log cause the problem? And please state your Gogs version, database and system. |
@unknwon here are the xorm log entries that show up when attempting to render the page:
|
It seems there are no error occupation? @johnnylee |
@lunny I'm not sure I understand. Looking at this information, I think that the most likely cause of the error is in the last query, where it appears that xorm is passing the array 1,2 to postgres as a string. |
func (org *User) GetUserRepositories(userID int64) (err error) {
teams := make([]*Team, 0, org.NumTeams)
if err = x.Sql(`SELECT team.id FROM team
INNER JOIN team_user ON team_user.team_id = team.id
WHERE team_user.org_id = ? AND team_user.uid = ?`, org.Id, userID).Find(&teams); err != nil {
return fmt.Errorf("get teams: %v", err)
}
args := make([]interface{}, 2+len(teams))
marks := make([]string, len(teams))
args[0], args[1] = org.Id, false
for i := range teams {
args[i+2] = com.ToStr(teams[i].ID)
marks[i] = "?"
}
if len(teams) == 0 {
// user has no team but "IN ()" is invalid SQL
args = append(args, "-1") // there is no repo with id=-1
marks = append(marks, "?")
}
repos := make([]*Repository, 0, 5)
if err = x.Sql(fmt.Sprintf(`SELECT repository.* FROM repository
INNER JOIN team_repo ON team_repo.repo_id = repository.id
WHERE (repository.owner_id = ? AND repository.is_private = ?) OR team_repo.team_id IN (%s)
GROUP BY repository.id`, strings.Join(marks, ", ")), args...).Find(&repos); err != nil {
return fmt.Errorf("get repositories: %v", err)
}
org.Repos = repos
// FIXME: should I change this value inside method,
// or only in location of caller where it's really needed?
org.NumRepos = len(org.Repos)
return nil
} |
@lunny any explanation for the patch? |
I suppose the explanation would be something like this: The SQL error is caused by the fact that a list of integers as a string ('1,2,3') cannot be used as a bind variable value in PostgreSQL for a statement like this: ...where x in (?). There might be some As @lunny suggested, an easy way out is to use fmt.Printf to embed the list if integers as part of the SQL statement and not use a bind variable at all. This may cause SQL injection issues though, so Here is my version which is a bit simpler. Seems to work fine on top of the current master. Provided just for reference and for anyone who wants to work around the problem while waiting for the final fix. diff --git a/models/org.go b/models/org.go
index 1fee4f5..f750822 100644
--- a/models/org.go
+++ b/models/org.go
@@ -1071,11 +1071,11 @@ WHERE team_user.org_id = ? AND team_user.uid = ?`, org.Id, userID).Find(&teams);
}
repos := make([]*Repository, 0, 5)
- if err = x.Sql(`SELECT repository.* FROM repository
+ if err = x.Sql(fmt.Sprintf(`SELECT repository.* FROM repository
INNER JOIN team_repo ON team_repo.repo_id = repository.id
-WHERE (repository.owner_id = ? AND repository.is_private = ?) OR team_repo.team_id IN (?)
-GROUP BY repository.id`,
- org.Id, false, strings.Join(teamIDs, ",")).Find(&repos); err != nil {
+WHERE (repository.owner_id = ? AND repository.is_private = ?) OR team_repo.team_id IN (%s)
+GROUP BY repository.id`, strings.Join(teamIDs, ",")),
+ org.Id, false).Find(&repos); err != nil {
return fmt.Errorf("get repositories: %v", err)
}
org.Repos = repos
--
2.1.4 |
I think it could be a problem PostgreSQL version too low... my PostgreSQL 9.5 instance could handle |
That's quite possible. My environment is Ubuntu server 15.04 with PostgreSQL 9.4. Good to hear that 9.5 is better. |
Close as fixed. |
I stumbled upon this issue today after installing gogs and setting things up. Do you plan on releasing the fix soon? 😃 Thanks a lot @unknwon |
@Toogy early next week I think... |
* Download and pushing translations * Adding empty line between build steps
Description
When I attempt to view a newly created organization, I get a 500 error. I see the following in the log file:
This is a fresh install with one user and one organization.
The text was updated successfully, but these errors were encountered: