Skip to content

Fix 500 in public#binary_packages for scmsync project packages - #20251

Open
Jarvis-J-Jacob wants to merge 2 commits into
openSUSE:masterfrom
Jarvis-J-Jacob:fix/20224-binary-packages-scmsync-nil
Open

Fix 500 in public#binary_packages for scmsync project packages#20251
Jarvis-J-Jacob wants to merge 2 commits into
openSUSE:masterfrom
Jarvis-J-Jacob:fix/20224-binary-packages-scmsync-nil

Conversation

@Jarvis-J-Jacob

Copy link
Copy Markdown

What

GET /public/binary_packages/:project/:package returns HTTP 500
(undefined method 'project' for nil) when the requested package belongs
to a project that uses scmsync — e.g.
https://api.opensuse.org/public/binary_packages/openSUSE:Leap:16.0/eza.

Why

Packages of scmsync projects live in the project's git repository, not
in the database. #binary_packages guards access with
check_package_access(..., use_source: false), which calls
Package.get_by_project_and_name(..., use_source: false). For a package
of an scmsync project that method returns nil instead of raising
(it only follows the scmsync link when follow_project_scmsync_links: true), so the guard passes. @pkg is then nil and the action crashes
at @pkg.project.repositories.

This adds a fallback: when the DB lookup returns nil, build a read-only
Package from the backend package meta
(follow_project_scmsync_links: true), which provides the project, its
repositories, and the package name/title/description the action renders.

Side effects

  • A request for a package that doesn't exist on the backend either now
    returns 404 (Package::UnknownObjectError) instead of 500.
  • No change for non-scmsync projects: the fallback only runs when the DB
    lookup returns nil, which for a normal missing package already raised
    in check_package_access before this line.
  • No migration, no config change, no feature toggle — nothing to do at
    deploy time.

How to verify

Automated (new spec GET #binary_packages for a package of an scmsync project; whole file green, 51 examples):

docker compose run --rm frontend bundle exec rspec spec/controllers/public_controller_spec.rb

Manual:

  1. Give a project an scmsync URL: edit the project meta and add
    <scmsync>https://example.com/whatever.git</scmsync> (web UI meta
    editor, or osc meta prj <project>).
  2. Request a package of that project that has no package entry in the
    database:
    curl -i http://localhost:3000/public/binary_packages//
  3. On master this responds 500. With this PR it responds 200 (or
    404 if the package also doesn't exist on the backend).

AI use is disclosed via the Assisted-by: trailer on the commit; the
change was reviewed and tested locally before submitting.

Fixes #20224

@github-actions github-actions Bot added the Frontend Things related to the OBS RoR app label Sep 2, 2026
Comment thread src/api/app/controllers/public_controller.rb Outdated
Packages of scmsync projects live in the project's git repository, not in
the database. #binary_packages guarded access with check_package_access
(use_source: false) and then looked @pkg up with a plain DB query, which
returns nil for a package of an scmsync project. @pkg stayed nil and the
action crashed at @pkg.project.repositories with "undefined method
'project' for nil" -> HTTP 500.

Look @pkg up with Package.get_by_project_and_name(use_source: false,
follow_project_scmsync_links: true) instead. It resolves the same database
packages the previous lookup did, and additionally builds a read-only
Package from the backend package meta for scmsync projects, providing the
project, its repositories and the name/title/description the action and
its view need.

Side effect: a request for a package that does not exist on the backend
now returns 404 (Package::UnknownObjectError) instead of 500. Non-scmsync
projects are unaffected: a normal missing package already raised in
check_package_access before this line.

Fixes openSUSE#20224
@Jarvis-J-Jacob
Jarvis-J-Jacob force-pushed the fix/20224-binary-packages-scmsync-nil branch from 2e3e710 to 0b729e8 Compare September 2, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Frontend Things related to the OBS RoR app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[production][public#binary_packages] undefined method 'project' for nil

2 participants