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

CountIssues: pq: invalid input syntax for type smallint: "true" #21447

Closed
zenofile opened this issue Oct 13, 2022 · 4 comments · Fixed by #21482
Closed

CountIssues: pq: invalid input syntax for type smallint: "true" #21447

zenofile opened this issue Oct 13, 2022 · 4 comments · Fixed by #21482
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/bug
Milestone

Comments

@zenofile
Copy link
Contributor

zenofile commented Oct 13, 2022

Description

After migrating from MariaDB to PostgreSQL using gitea dump -d postgres, Gitea produces a status code 500 upon visiting https://example.org/notifications/subscriptions.

The error reported in the log is:

...user/notification.go:256:NotificationSubscriptions() [I] [63485399] [SQL] SELECT COUNT(issue.id) AS count FROM "issue" INNER JOIN "repository" ON "issue".repo_id = "repository".id WHERE issue.id NOT IN (SELECT issue_id FROM issue_watch WHERE is_watching=$1 AND user_id=$2) AND (issue.id IN (SELECT issue_id FROM issue_watch WHERE is_watching=$3 AND user_id=$4) OR issue.id IN (SELECT issue_id FROM comment WHERE poster_id=$5) OR issue.poster_id=$6 OR issue.repo_id IN (SELECT id FROM watch WHERE mode=$7 AND user_id=$8)) [false 1 true 1 1 1 true 1] - 577.586µs
...user/notification.go:263:NotificationSubscriptions() [E] [63485399] CountIssues: pq: invalid input syntax for type smallint: "true"

Manually issuing the query produces:

 gitea=>  SELECT COUNT(issue.id) AS count FROM "issue" INNER JOIN "repository" ON "issue".repo_id = "repository".id WHERE issue.id NOT IN (SELECT issue_id FROM issue_watch WHERE is_watching=false AND user_id=1) AND (issue.id IN (SELECT issue_id FROM issue_watch WHERE is_watching=true AND user_id=1) OR issue.id IN (SELECT issue_id FROM comment WHERE poster_id=1) OR issue.poster_id=1 OR issue.repo_id IN (SELECT id FROM watch WHERE mode=true AND user_id=1));
ERROR:  operator does not exist: smallint = boolean
LINE 1: ... issue.repo_id IN (SELECT id FROM watch WHERE mode=true AND ...
                                                             ^

This seems to be the only issue I encountered after migration.

Gitea Version

1.18.0+dev-548-g6a6dc97b0

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

https://gist.github.com/zenofile/6cdef4553a55bcbebff6135a31511a6d

Screenshots

image

Git Version

2.36.2

Operating System

Fedora Linux 37

How are you running Gitea?

As a podman (docker) container, migrated from MariaDB to PostgreSQL.

Database

PostgreSQL

@lafriks
Copy link
Member

lafriks commented Oct 13, 2022

You need to change smallint columns to bool

@zenofile
Copy link
Contributor Author

You need to change smallint columns to bool

I understand that postgres does use boolean values instead of smallints, but which smallint columns are you referring to?

Taking a look at

const (
// WatchModeNone don't watch
WatchModeNone WatchMode = iota // 0
// WatchModeNormal watch repository (from other sources)
WatchModeNormal // 1
// WatchModeDont explicit don't auto-watch
WatchModeDont // 2
// WatchModeAuto watch repository (from AutoWatchOnChanges)
WatchModeAuto // 3
)
// Watch is connection request for receiving repository notification.
type Watch struct {
ID int64 `xorm:"pk autoincr"`
UserID int64 `xorm:"UNIQUE(watch)"`
RepoID int64 `xorm:"UNIQUE(watch)"`
Mode WatchMode `xorm:"SMALLINT NOT NULL DEFAULT 1"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
}
mode does not seem to be intended as a boolean value like the query suggests.

@lafriks
Copy link
Member

lafriks commented Oct 13, 2022

sorry you are right. It's actually bug in this line:
https://github.com/go-gitea/gitea/blob/main/models/issues/issue.go#L1495

@wxiaoguang wxiaoguang added the issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented label Oct 14, 2022
@wxiaoguang wxiaoguang added this to the 1.18.0 milestone Oct 14, 2022
@lafriks
Copy link
Member

lafriks commented Oct 17, 2022

Shouldn't filter only 1 and 3? Not sure tho if 2 means to not watch? 🤔

6543 pushed a commit that referenced this issue Oct 18, 2022
Fix enumeration of user subscriptions. `watch.mode` is not a boolean but
a smallint.

Fixes #21447
Regression of #17156
@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.
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants