Skip to content

Fix the package versions scope

David Fernandez requested to merge 374295-fix-package-other-versions into master

🐗 Context

In simplified terms, the GitLab Package Registry organizes packages in tuples: {package_name, version} (we have other fields but they are not relevant to this context).

(A) One thing that the UI presents is when browsing a specific package version, it will show the other versions of that package. For example, let's say that we have: {foobar, 1.2.3}, {foobar, 1.2.4}, {foobar, 1.2.5}. When browsing {foobar, 1.2.4}, the UI will present that we have 2 other versions: {foobar, 1.2.3}, {foobar, 1.2.5}.

(B) Deleting a package in the Package Registry is not as simple as package.destroy! and done! That package can have many package files and each package file is associated with one file on Object Storage. As such, we implemented a mark and delete system where packages are marked as pending_destruction, then background jobs will slowly (or at lease at their own pace) destroy all the files and once done, the related package. It is worth noting that pending_destruction packages disappear from the UI: users can't see them in the UI, APIs (rest and GraphQL) and certainly can't pull them (with commands like $ npm install).

It seems that we forgot a code location when (B) was implemented, (A) is still showing pending_destruction packages. That's a plain typebug.

This has been reported when verifying #374295 (comment 1259248444).

This MR fixes that situation.

🔍 What does this MR do and why?

  • Fixes the package.versions scope so that pending_destruction packages (or even other statuses) are excluded.
    • More accurately, only displayable packages will be returned.
  • Updates the related specs.

📺 Screenshots or screen recordings

Visiting the versions tab of a package details

On master:

Screenshot_2023-01-31_at_17.44.06

With this MR:

Screenshot_2023-01-31_at_17.44.05

The count and the actual packages shown is correct!

How to set up and validate locally

In a rails console:

  1. Define a helper function:
    def fixture_file_upload(*args, **kwargs)
      Rack::Test::UploadedFile.new(*args, **kwargs)
    end
  2. Let's create 5 different versions:
    5.times { |i| FactoryBot.create(:generic_package, project: Project.first, name: "test", version: "1.2.#{i}") }
  3. Let's flag the very first package as error:
    Project.first.packages.order_by(:id).first.update!(status: :error)
  4. Let's flag the second package as as pending_destruction:
    Project.first.packages.order_by(:id).second.update!(status: :pending_destruction)
  5. You can verify the status with:
    Project.first.packages.order_by(:id)

Setup is complete. Now, let's browse the very last version of the package:

  1. Go to <gdk_base_url>/gitlab-org/gitlab-test/-/packages
  2. Click on version 1.2.4.
  3. Towards the top, click on Other versions.
    • You should see only 3 versions:
      • 1.2.0 is in error but that is still displayable.
      • 1.2.2 is in default and is displayed.
      • 1.2.3 is in default and is displayed.
    • Notice that we don't see 1.2.1 which is in pending_destruction and thus, not displayed.

The change is working as expected 🎉

🏎 MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

💾 Database analysis

Edited by David Fernandez

Merge request reports