Skip to content

Commit c40c753

Browse files
lunnyzeripath
andauthored
Check Mirror exists before linking its Repo (#20840) (#20842)
In MirrorRepositoryList.loadAttributes there is some code to load the Mirror entries from the database. This assumes that every Repository which has IsMirror set has a Mirror associated in the DB. This association is incorrect in the case of Mirror repository under creation when there is no Mirror entry in the DB until completion. Unfortunately LoadAttributes makes this incorrect assumption and presumes that a Mirror will always be loaded. This then causes a panic. This PR simply double checks if there a Mirror before attempting to link back to its Repo. Unfortunately it should be expected that there may be other cases where this incorrect assumption causes further problems. Fix #20804 Signed-off-by: Andrew Thornton <[email protected]> Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: Lunny Xiao <[email protected]> Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: zeripath <[email protected]>
1 parent 7a9b01a commit c40c753

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

models/repo/mirror.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ func (repos MirrorRepositoryList) loadAttributes(ctx context.Context) error {
153153
}
154154
for i := range repos {
155155
repos[i].Mirror = set[repos[i].ID]
156-
repos[i].Mirror.Repo = repos[i]
156+
if repos[i].Mirror != nil {
157+
repos[i].Mirror.Repo = repos[i]
158+
}
157159
}
158160
return nil
159161
}

0 commit comments

Comments
 (0)