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

Migration issue: PRs broken after upgrade to 1.17.0 #20826

Closed
wolfbeast opened this issue Aug 17, 2022 · 19 comments · Fixed by #22512
Closed

Migration issue: PRs broken after upgrade to 1.17.0 #20826

wolfbeast opened this issue Aug 17, 2022 · 19 comments · Fixed by #22512
Labels
Milestone

Comments

@wolfbeast
Copy link

Description

After upgrading from 1.12.6 to 1.17.0, I'm running into an issue where any mergable PRs result in server error 500s. Merged PRs and WIP PRs display normally.

Relevant log lines:

2022/08/17 10:58:16 ...vices/pull/update.go:109:IsUserAllowedToUpdate() [E] [62fcc9c8] pr.BaseRepo.GetUnit(unit.TypePullRequests): Unit type does not exist: TypePullRequests
2022/08/17 10:58:16 ...ers/web/repo/pull.go:509:PrepareViewPullInfo() [E] [62fcc9c8] IsUserAllowedToUpdate: Unit type does not exist: TypePullRequests

I followed to recommended upgrade procedure (and also removed any custom templates we had in use previously). The upgrade seems to have gone OK otherwise. gitea doctor also doesn't show anything wrong.

If possible, a "quick fix" as a workaround for this error would be appreciated as we're currently unable to perform any merges in gitea which is a showstopper.

Gitea Version

1.17.0

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

2.37.1

Operating System

CentOS Linux 7.9.2009

How are you running Gitea?

From binary downloaded from gitea.io

Database

MySQL

@lunny
Copy link
Member

lunny commented Aug 17, 2022

You have to manually insert some record into repo_unit table.

@wolfbeast
Copy link
Author

What do I need to insert, exactly?

@wolfbeast
Copy link
Author

wolfbeast commented Aug 17, 2022

OK thanks to some help from the gitea discord I figured out the root cause of this problem.
The issues is that the migration apparently flipped off "enable pull requests" for the fork the PR was made upstream from. With the fork's setting having PRs off, the PR on the upstream repo throws a 500 in 1.17.0
Going into the fork's setting to enable PRs to the forked repo, it fixes the error on the parent repo.

This is definitely a bug - parent repo PRs should not depend on whether forks have certain settings enabled on them or not, and certainly shouldn't be throwing a server error as a result ;-)

EDIT: See also #20621

@lunny
Copy link
Member

lunny commented Aug 18, 2022

should be fixed by #20839

@lunny lunny added this to the 1.17.2 milestone Aug 18, 2022
@morph027
Copy link

We are running 1.17.1 already and the issue still persists.

@zeripath
Copy link
Contributor

zeripath commented Sep 4, 2022

You need to update the repos involved to enable the PullRequests unit

@wolfbeast
Copy link
Author

You need to update the repos involved to enable the PullRequests unit

I would have expected that to occur with the db migration, so there is a potential solution that doesn't involve having to manually have people of every fork go into their repo settings to make this happen and not get stuck on this when they try to make a PR further down the line.

@lunny lunny modified the milestones: 1.17.2, 1.17.3 Sep 5, 2022
@kakra
Copy link

kakra commented Sep 12, 2022

You need to update the repos involved to enable the PullRequests unit

Why do the forks need to have "pull requests" enabled when we only want pull requests on the parent? This issue still persists for us with 1.17.1. The only work around is to enable pull requests on the forks the individual PR originates from.

@6543 6543 modified the milestones: 1.17.3, 1.17.4 Oct 13, 2022
@cthu1hoo
Copy link

We just ran into this issue on dev.tt-rss.org. Asking people to enable PRs for their fork so that filing a PR against master repo wouldn't crash gitea with a 500 error seems incredibly strange to me.

Another strange thing is that PR was rendered properly until I logged in to review it, which is when everything just broke.

Hoping for a proper fix.

@lunny
Copy link
Member

lunny commented Nov 14, 2022

We just ran into this issue on dev.tt-rss.org. Asking people to enable PRs for their fork so that filing a PR against master repo wouldn't crash gitea with a 500 error seems incredibly strange to me.

Another strange thing is that PR was rendered properly until I logged in to review it, which is when everything just broke.

Hoping for a proper fix.

Do you have any logs?

@cthu1hoo
Copy link

cthu1hoo commented Nov 14, 2022

Sure, here's some container logs:

2022/11/12 19:34:46 ...ers/web/repo/pull.go:509:PrepareViewPullInfo() [E] [636fcb26-16] IsUserAllowedToUpdate: Unit type does not exist: TypePullRequests
2022/11/12 19:34:59 ...vices/pull/update.go:112:IsUserAllowedToUpdate() [E] [636fcb33] pr.BaseRepo.GetUnit(unit.TypePullRequests): Unit type does not exist: TypePullRequests
2022/11/12 19:34:59 ...ers/web/repo/pull.go:509:PrepareViewPullInfo() [E] [636fcb33] IsUserAllowedToUpdate: Unit type does not exist: TypePullRequests
2022/11/12 19:35:01 ...vices/pull/update.go:112:IsUserAllowedToUpdate() [E] [636fcb35] pr.BaseRepo.GetUnit(unit.TypePullRequests): Unit type does not exist: TypePullRequests
2022/11/12 19:35:01 ...ers/web/repo/pull.go:509:PrepareViewPullInfo() [E] [636fcb35] IsUserAllowedToUpdate: Unit type does not exist: TypePullRequests
2022/11/12 19:35:15 ...vices/pull/update.go:112:IsUserAllowedToUpdate() [E] [636fcb43] pr.BaseRepo.GetUnit(unit.TypePullRequests): Unit type does not exist: TypePullRequests
2022/11/12 19:35:15 ...ers/web/repo/pull.go:509:PrepareViewPullInfo() [E] [636fcb43] IsUserAllowedToUpdate: Unit type does not exist: TypePullRequests
2022/11/12 19:36:15 ...vices/pull/update.go:112:IsUserAllowedToUpdate() [E] [636fcb7f] pr.BaseRepo.GetUnit(unit.TypePullRequests): Unit type does not exist: TypePullRequests
2022/11/12 19:36:15 ...ers/web/repo/pull.go:509:PrepareViewPullInfo() [E] [636fcb7f] IsUserAllowedToUpdate: Unit type does not exist: TypePullRequests
2022/11/12 19:36:28 ...vices/pull/update.go:112:IsUserAllowedToUpdate() [E] [636fcb8c] pr.BaseRepo.GetUnit(unit.TypePullRequests): Unit type does not exist: TypePullRequests
2022/11/12 19:36:28 ...ers/web/repo/pull.go:509:PrepareViewPullInfo() [E] [636fcb8c] IsUserAllowedToUpdate: Unit type does not exist: TypePullRequests
2022/11/12 19:37:27 ...vices/pull/update.go:112:IsUserAllowedToUpdate() [E] [636fcbc7] pr.BaseRepo.GetUnit(unit.TypePullRequests): Unit type does not exist: TypePullRequests
2022/11/12 19:37:27 ...ers/web/repo/pull.go:509:PrepareViewPullInfo() [E] [636fcbc7] IsUserAllowedToUpdate: Unit type does not exist: TypePullRequests
2022/11/12 19:37:57 ...vices/pull/update.go:112:IsUserAllowedToUpdate() [E] [636fcbe5] pr.BaseRepo.GetUnit(unit.TypePullRequests): Unit type does not exist: TypePullRequests
2022/11/12 19:37:57 ...ers/web/repo/pull.go:509:PrepareViewPullInfo() [E] [636fcbe5] IsUserAllowedToUpdate: Unit type does not exist: TypePullRequests

I thought the DB was broken somehow but then I found this issue and asked the contributor to enable PRs on his repo, he did, which stopped the crashes.

edit: no stacktrace or anything in logs, just a few more repeats of above lines.

@techknowlogick
Copy link
Member

@cthu1hoo if I'm not mistaken, did you switch your install from gogs?

@kakra
Copy link

kakra commented Nov 14, 2022

Same here, the install has always been native Gitea... If a fork doesn't allow PRs, you cannot view PRs submitted for the parent repository.

@cthu1hoo
Copy link

I'm not mistaken, did you switch your install from gogs?

yes, you're right. I did switch from gogs, a while ago.

@zeripath
Copy link
Contributor

Go to the base repository, then go to settings, then click on Enable Repository Pull Requests.

@zeripath
Copy link
Contributor

I wonder if you were affected by #16961?

@cthu1hoo
Copy link

Go to the base repository, then go to settings, then click on Enable Repository Pull Requests.

already enabled.

@pilou-
Copy link
Contributor

pilou- commented Dec 18, 2022

I encounter the same issue with Gitea 1.17.3:

  1. A public repository has been created in July 2021 (Gitea 1.14.3 was being used). Pull requests on the repository are enabled.
  2. Since, Gitea has been regularly updated: 1.17.3 is used since several weeks.
  3. Yesterday, the repository mentioned in the first step was forked. Pull requests on this fork are disabled.
  4. A pull request targeting the first repository has been created.
  5. =>
    • The error (HTTP 500) occurs when a logged used display the page related to this pull request.
    • If not authenticated, the error doesn't occur.

Enabling pull requests on the fork or enabling branch protection on the source branch of the merge request allows to workaround the issue.

The logs:

2022/12/18 23:46:57 ...vices/pull/update.go:112:IsUserAllowedToUpdate() [E] [639f9861-2] pr.BaseRepo.GetUnit(unit.TypePullRequests): Unit type does not exist: TypePullRequests
2022/12/18 23:46:57 ...ers/web/repo/pull.go:509:PrepareViewPullInfo() [E] [639f9861-2] IsUserAllowedToUpdate: Unit type does not exist: TypePullRequests

The database content (270 is the id of the repository created in July 2021, 785 is the fork):

giteadb=# select * from repo_unit where (repo_id=785 or repo_id=270) ;
 id  | repo_id | type |                                                                                   config                                                                                   | created_unix 
------+---------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------
 1671 |     270 |    1 |                                                                                                                                                                            |   1625507803
 1672 |     270 |    2 | {"EnableTimetracker":false,"AllowOnlyContributorsToTrackTime":true,"EnableDependencies":true}                                                                              |   1625507803
 1673 |     270 |    3 | {"IgnoreWhitespaceConflicts":false,"AllowMerge":true,"AllowRebase":true,"AllowRebaseMerge":true,"AllowSquash":true,"AllowManualMerge":false,"AutodetectManualMerge":false} |   1625507803
 1674 |     270 |    4 |                                                                                                                                                                            |   1625507803
 1675 |     270 |    5 |                                                                                                                                                                            |   1625507803
 1676 |     270 |    8 |                                                                                                                                                                            |   1625507803
 4845 |     785 |    1 |                                                                                                                                                                            |   1671384984
 4848 |     785 |    4 |                                                                                                                                                                            |   1671384984

The gitea doctor --all command doesn't report any related warning/error.

@lunny
Copy link
Member

lunny commented Dec 19, 2022

Looks like something(unit 2, 3, 5, 8) missed for forked repository.

jolheiser pushed a commit that referenced this issue Jan 18, 2023
…ed (#22512)

Swallow error just like in #20839, for the case where there is no
protected branch.

Fixes #20826 for me, though I can't tell if this now covers all cases.
jolheiser pushed a commit to jolheiser/gitea that referenced this issue Jan 18, 2023
…ed (go-gitea#22512)

Swallow error just like in go-gitea#20839, for the case where there is no
protected branch.

Fixes go-gitea#20826 for me, though I can't tell if this now covers all cases.
@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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants