Skip to content

Redirect renamed project slugs in API v2 project endpoint (fixes #4182)#4295

Open
eshu3104 wants to merge 2 commits into
mozilla:mainfrom
eshu3104:fix-4182-api-slug-redirect
Open

Redirect renamed project slugs in API v2 project endpoint (fixes #4182)#4295
eshu3104 wants to merge 2 commits into
mozilla:mainfrom
eshu3104:fix-4182-api-slug-redirect

Conversation

@eshu3104

@eshu3104 eshu3104 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

/api/v2/projects/<old-slug>/ returned a 404 for renamed projects, while the
web UI redirects to the new slug. This adds a retrieve() override to
ProjectIndividualView with the same ProjectSlugHistory fallback: on a
failed lookup, respond with a 302 to the current slug's URL. Unknown slugs
still return 404.

The fallback logic mirrors get_project_or_redirect() in
pontoon/base/services.py. The 404 path now runs one extra history query,
hence the query-count update in test_disabled_project.

Tests: test_project_renamed_slug_redirects (old slug returns a 302 with the
correct Location) and test_project_unknown_slug_404s.

Note: other slug-based endpoints and locale endpoints (via LocaleCodeHistory)
have the same gap. This PR only covers the endpoint from the issue; happy to
follow up on the rest.

@flodolo flodolo requested a review from functionzz July 7, 2026 14:26

@functionzz functionzz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, if possible, can you extend the behavior to the /api/v2/locales/<locale_code> & /api/v2/<locale_code>/<project_slug> endpoints? The LocaleCodeHistory & ProjectSlugHistory models will be useful :).

You will need to edit the behavior of LocaleIndividualView & ProjectLocaleIndividualView in a similar manner as you have done here.

Comment thread pontoon/api/tests/test_views.py Outdated
Co-authored-by: Jamie <164675620+functionzz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants