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

restore-repo: issue comments are no longer imported #22581

Closed
drsybren opened this issue Jan 23, 2023 · 6 comments · Fixed by #22776
Closed

restore-repo: issue comments are no longer imported #22581

drsybren opened this issue Jan 23, 2023 · 6 comments · Fixed by #22776
Labels
Milestone

Comments

@drsybren
Copy link
Contributor

drsybren commented Jan 23, 2023

Description

Since 71ca306 issue comments are no longer imported with gitea restore-repo.

See func (r *RepositoryRestorer) GetComments(...) in services/migrations/restore.go , it still uses commentable.GetForeignIndex() (link) but as far as I can see that foreign index isn't loaded any more since that commit.

This patches things up for me locally, but I don't know if this is the right thing to do:

diff --git a/services/migrations/restore.go b/services/migrations/restore.go
index fd337b22c..6ee878a64 100644
--- a/services/migrations/restore.go
+++ b/services/migrations/restore.go
@@ -198,7 +198,7 @@ func (r *RepositoryRestorer) GetIssues(page, perPage int) ([]*base.Issue, bool,
 // GetComments returns comments according issueNumber
 func (r *RepositoryRestorer) GetComments(commentable base.Commentable) ([]*base.Comment, bool, error) {
        comments := make([]*base.Comment, 0, 10)
-       p := filepath.Join(r.commentDir(), fmt.Sprintf("%d.yml", commentable.GetForeignIndex()))
+       p := filepath.Join(r.commentDir(), fmt.Sprintf("%d.yml", commentable.GetLocalIndex()))
        _, err := os.Stat(p)
        if err != nil {
                if os.IsNotExist(err) {

To reproduce the issue, unzip demo-repo-22581.zip, then run gitea restore-repo -r /path/to/demo-repo-22581 --owner_name youruser --repo_name demo-repo-22581

When visiting the repo in Gitea's web interface, you'll notice that there is one imported issue, but no comments, even though there is a corresponding file in demo-repo-22581/comment/104010.yml.

There's nothing about this in the logs.

Gitea Version

29b78bc

How are you running Gitea?

Self-built from the main branch.

Database

PostgreSQL

drsybren added a commit to blender/gitea that referenced this issue Jan 23, 2023
Workaround for a bug in Gitea that blocks us from importing comments.

This works for us, no idea whether it's the right approach, though.

Tracked upstream at go-gitea#22581
@lunny lunny added this to the 1.19.0 milestone Jan 23, 2023
@zeripath
Copy link
Contributor

zeripath commented Jan 24, 2023

Hmm... My original suggestion was to simply add a primary key to that table and IIRC correctly my code to do that was even removed from that PR and therefore I should not have been left on the commit as an author.

IIRC it was later decided that the foreign reference wasn't used anywhere and it was simpler to drop the table completely. I don't know this code very well so I don't understand why and wherefore this was added.

@wxiaoguang IIRC you said to remove this table?

@zeripath
Copy link
Contributor

Now looking at #18446. ForeignReference was added as a way to keep a match between a migrated repo issue id and pull id and its original repo. The idea presumably being that it would help in future to auto add incremental migrations and federation etc.

Of course the problem is whether the ForeignReference is actually helpful for that - possibly not as it may need to have the actual url for the entity that is referencing, but I'm not certain.


Now I don't fully understand why the code in #21721 would break things. @drsybren could you please give clear instructions on how to reproduce your issue and report any logs?

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jan 25, 2023

Maybe the PR #21721 missed something (hmm, it's caused by an old bug in history). If @wolfogre doesn't have time, I can take it.


ps: I think the patch in the first comment could be right. We can take it, but need to clarify all details (see the comment below)

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jan 25, 2023

About why:

Now I don't fully understand why the code in 21721 would break things.

Actually, I think it's caused by some PRs before 18446. If I understand correctly, there was an IssueContext, which has ForeignID() and LocalID(), they all returned the same result at that time. However, that design also seems to be flawed, and using ForeignID for issue yaml files seems to be incorrect: The exported files are named by the original repo's issue ID -- which is likely to be LocalID.

The root problem is: the ForeignID and LocalID were already ambiguity. For example, if site-a exports a dataset, then site-b imports it:

  • site-a exports files by using its LocalID
  • from site-a's view, LocalID is site-a's ID while ForeignID is site-b's ID
  • but from site-b's view, LocalID is site-b's ID while ForeignID is site-a's ID

Maybe I misunderstood something , but indeed the design really seemed misleading for me.


In history, that's all correct: fmt.Sprintf("%d.yml", opts.IssueNumber))

https://github.com/realaravinth/gitea/blame/2d1935acc7b2a6ecc797346625b80caa7e0b5787/modules/migrations/restore.go

But #16356 introduced IssueContext and started using ForeignID. At that time ForeignID was LocalID, so the design bug didn't cause problems. But now, the bug finally causes problems.

@drsybren
Copy link
Contributor Author

drsybren commented Jan 26, 2023

To reproduce the issue, unzip demo-repo-22581.zip, then run gitea restore-repo -r /path/to/demo-repo-22581 --owner_name youruser --repo_name demo-repo-22581

When visiting the repo in Gitea's web interface, you'll notice that there is one imported issue, but no comments, even though there is a corresponding file in demo-repo-22581/comment/104010.yml.

There's nothing about this in the logs.

@wxiaoguang
Copy link
Contributor

Fix restore repo bug, clarify the problem of ForeignIndex #22776

lunny pushed a commit that referenced this issue Feb 7, 2023
Fix #22581

TLDR: #18446 made a mess with ForeignIndex and triggered a design
flaw/bug of #16356, then a quick patch #21271 helped #18446, then the
the bug was re-triggered by #21721 .

Related:
* #16356
* BasicIssueContext
https://github.com/go-gitea/gitea/pull/16356/files#diff-7938eb670d42a5ead6b08121e16aa4537a4d716c1cf37923c70470020fb9d036R16-R27
* #18446 
* If some issues were dumped without ForeignIndex, then they would be
imported as ForeignIndex=0
https://github.com/go-gitea/gitea/pull/18446/files#diff-1624a3e715d8fc70edf2db1630642b7d6517f8c359cc69d58c3958b34ba4ce5eR38-R39
* #21271
* It patched the above bug (somewhat), made the issues without
ForeignIndex could have the same value as LocalIndex
* #21721 
    * It re-triggered the zero-ForeignIndex bug.


ps: I am not sure whether the changes in `GetForeignIndex` are ideal (at
least, now it has almost the same behavior as BasicIssueContext in
#16356), it's just a quick fix. Feel free to edit on this PR directly or
replace it.

Co-authored-by: zeripath <art27@cantab.net>
yardenshoham pushed a commit to yardenshoham/gitea that referenced this issue Feb 7, 2023
…2776)

Fix go-gitea#22581

TLDR: go-gitea#18446 made a mess with ForeignIndex and triggered a design
flaw/bug of go-gitea#16356, then a quick patch go-gitea#21271 helped go-gitea#18446, then the
the bug was re-triggered by go-gitea#21721 .

Related:
* go-gitea#16356
* BasicIssueContext
https://github.com/go-gitea/gitea/pull/16356/files#diff-7938eb670d42a5ead6b08121e16aa4537a4d716c1cf37923c70470020fb9d036R16-R27
* go-gitea#18446 
* If some issues were dumped without ForeignIndex, then they would be
imported as ForeignIndex=0
https://github.com/go-gitea/gitea/pull/18446/files#diff-1624a3e715d8fc70edf2db1630642b7d6517f8c359cc69d58c3958b34ba4ce5eR38-R39
* go-gitea#21271
* It patched the above bug (somewhat), made the issues without
ForeignIndex could have the same value as LocalIndex
* go-gitea#21721 
    * It re-triggered the zero-ForeignIndex bug.


ps: I am not sure whether the changes in `GetForeignIndex` are ideal (at
least, now it has almost the same behavior as BasicIssueContext in
go-gitea#16356), it's just a quick fix. Feel free to edit on this PR directly or
replace it.

Co-authored-by: zeripath <art27@cantab.net>
zeripath pushed a commit that referenced this issue Feb 8, 2023
…22794)

Backport #22776

Fix #22581

TLDR: #18446 made a mess with ForeignIndex and triggered a design
flaw/bug of #16356, then a quick patch #21271 helped #18446, then the
the bug was re-triggered by #21721 .

Related:
* #16356
* BasicIssueContext
https://github.com/go-gitea/gitea/pull/16356/files#diff-7938eb670d42a5ead6b08121e16aa4537a4d716c1cf37923c70470020fb9d036R16-R27
* #18446 
* If some issues were dumped without ForeignIndex, then they would be
imported as ForeignIndex=0
https://github.com/go-gitea/gitea/pull/18446/files#diff-1624a3e715d8fc70edf2db1630642b7d6517f8c359cc69d58c3958b34ba4ce5eR38-R39
* #21271
* It patched the above bug (somewhat), made the issues without
ForeignIndex could have the same value as LocalIndex
* #21721 
    * It re-triggered the zero-ForeignIndex bug.


ps: I am not sure whether the changes in `GetForeignIndex` are ideal (at
least, now it has almost the same behavior as BasicIssueContext in
#16356), it's just a quick fix. Feel free to edit on this PR directly or
replace it.

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@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.

4 participants