Skip to content

Fixed bug with wiki operations enumerator when content nil

Because of https://gitlab.com/gitlab-org/gitlab-ce/issues/49889 I discovered there is a bug when the wiki page content is nil.

Right now, from the UI is not possible to create wiki pages with empty content, but we'll able to do that through Git. Let's take a look at WikiService#wiki_get_all_pages:

Enumerator.new do |y|
  wiki.pages(limit: pages_limit).each do |page|
    gitaly_wiki_page = build_gitaly_wiki_page(page)

    io = StringIO.new(page.text_data)
    while chunk = io.read(Gitlab.config.git.write_buffer_size)
      gitaly_wiki_page.raw_data = chunk

      y.yield Gitaly::WikiGetAllPagesResponse.new(page: gitaly_wiki_page)

      gitaly_wiki_page = build_gitaly_wiki_page
    end

    y.yield Gitaly::WikiGetAllPagesResponse.new(end_of_page: true)
  end
end

Now imagine we have a list of pages, page1 with content nil and page2 with content foobar. When we start iterating, because page1 does not have content the response y.yield Gitaly::WikiGetAllPagesResponse.new(page: gitaly_wiki_page) won't be sent, but y.yield Gitaly::WikiGetAllPagesResponse.new(end_of_page: true) will. In the platform, when we try to retrieve the pages from the enumerator, it will see the end_of_page and it will end retrieving more pages.

This problem ocurrs with several wiki operations.

There is a different approach that the one I took in this MR. That would be to change in WikiPage#formatted_data, WikiPage#text_data and WikiFile@raw_data and return if no content is found, but I prefered not to touch the content.

Edited by GitLab Release Tools Bot

Merge request reports