Fix the package versions scope
🐗 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 thatpending_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
:
With this MR:
The count and the actual packages shown is correct!
⚙ How to set up and validate locally
In a rails console:
- Define a helper function:
def fixture_file_upload(*args, **kwargs) Rack::Test::UploadedFile.new(*args, **kwargs) end
- Let's create 5 different versions:
5.times { |i| FactoryBot.create(:generic_package, project: Project.first, name: "test", version: "1.2.#{i}") }
- Let's flag the very first package as
error
:Project.first.packages.order_by(:id).first.update!(status: :error)
- Let's flag the second package as as
pending_destruction
:Project.first.packages.order_by(:id).second.update!(status: :pending_destruction)
- 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:
- Go to
<gdk_base_url>/gitlab-org/gitlab-test/-/packages
- Click on version
1.2.4
. - Towards the top, click on
Other versions
.- You should see only 3
versions
:-
1.2.0
is inerror
but that is still displayable. -
1.2.2
is indefault
and is displayed. -
1.2.3
is indefault
and is displayed.
-
- Notice that we don't see
1.2.1
which is inpending_destruction
and thus, not displayed.
- You should see only 3
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.
-
I have evaluated the MR acceptance checklist for this MR.