Skip to content

Fix Incorrect URL Links In Wagtail Based On Browser Language#1485

Draft
dchukhin wants to merge 1 commit into
mainfrom
fallback-locale-bug
Draft

Fix Incorrect URL Links In Wagtail Based On Browser Language#1485
dchukhin wants to merge 1 commit into
mainfrom
fallback-locale-bug

Conversation

@dchukhin

@dchukhin dchukhin commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

One-line summary

When a user's profile in Wagtail (or their browser language) is set to an alias locale, some links in Wagtail incorrectly point to the alias locale.

Significant changes and points to review

  • a new WagtailAdminRequestMiddleware tracks if the request is for a Wagtail admin URL
  • AbstractSpringfieldCMSPage.get_url_parts() explicitly overrides the locale if 1. the request is for a Wagtail admin URL and 2. the locale does not match the page's locale (as a note, there is no public-facing behavior change here)
  • a WAGTAIL_ADMIN_URL_PREFIX setting for the Wagtail admin prefix (no behavior change here, just setting this in settings, so it can be used in another file)
  • tests for this behavior, including for the rich text block

Issue / Bugzilla link

Testing

Steps to recreate the bug:

  1. Log in to Wagtail, go to /cms-admin/account/ → Language preferences → set preferred language to Portuguese (the pt-pt option) → Save.
  2. Open the edit view of a published pt-BR page (for example, the pt-BR thanks page: http://localhost:8000/cms-admin/pages/466/edit/).
  3. observe that the page is published
  4. observe that the "PUBLICADA" link points to the pt-PT page (http://localhost:8000/pt-PT/thanks/) instead of the pt-BR page
  5. Switch the account language back to English, and reload the pt-BR thanks page, and observe that the link correctly points to the pt-BR page (http://localhost:8000/pt-BR/thanks/)

To test the fix, follow the same steps, but observe that the "PUBLICADA" link points to the pt-BR page.

@dchukhin dchukhin marked this pull request as draft June 8, 2026 22:16
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.34%. Comparing base (0958159) to head (ae63331).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1485      +/-   ##
==========================================
+ Coverage   79.26%   79.34%   +0.07%     
==========================================
  Files         154      154              
  Lines       10569    10592      +23     
==========================================
+ Hits         8378     8404      +26     
+ Misses       2191     2188       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant