Skip to content

Add workaround for live button URL in admin panel#549

Open
MaciekBaron wants to merge 2 commits intomainfrom
fix/cms-1140-live-button
Open

Add workaround for live button URL in admin panel#549
MaciekBaron wants to merge 2 commits intomainfrom
fix/cms-1140-live-button

Conversation

@MaciekBaron
Copy link
Copy Markdown
Contributor

What is the context of this PR?

This PR addresses the bug raised in CMS-1140 and adds a workaround for the issue.

When CMS_USE_SUBDOMAIN_LOCALES is disabled (the default for local development), the admin "Live" button on pages pointed to the wrong host (e.g. http://cy.web.ons.orb.local:8000/) because _get_site_root_paths fell back to Wagtail's default Site.get_site_root_paths(), which returned all Site records from the database, including those with production/staging hostnames loaded from CMS_HOSTNAME_LOCALE_MAP in .env. Note that other "Live" buttons would work correctly.

The workaround routes the non-subdomain code path through get_mapped_site_root_paths(default_site_only=True) instead, which filters to the default site and uses WAGTAILADMIN_BASE_URL as the root URL. This ensures the Live button points to http://localhost:8000 (or whatever you use) in development, regardless of what hostnames are stored in the database. This works if and only if one domain is being used to access the site (which should be true when CMS_USE_SUBDOMAIN_LOCALES is disabled).

How to review

  1. Ensure that CMS_USE_SUBDOMAIN_LOCALES is disabled
  2. Go to an admin view such as /admin/pages/3/
  3. Click or inspect the "Live" button in the top right corner
  4. Confirm that the correct URL is being used (e.g. "localhost:8000", not the subdomain)
  5. Change your local settings to enable CMS_USE_SUBDOMAIN_LOCALES and reload the server
  6. Return to the same admin view (or refresh the page)
  7. Confirm that the correct URL is being used (e.g. "web.ons.orb.local:8000", the subdomain)

Deployment Safety

Bleed and Sandbox deploy automatically on merge, so PRs should be safe to deploy immediately.

Please select one:

  • Safe to auto-deploy
  • Not safe to auto-deploy

Follow-up Actions

Ensure this change introduces no regressions.

@MaciekBaron MaciekBaron requested a review from a team as a code owner March 25, 2026 11:02
Comment thread cms/locale/utils.py
"""
swap_domains: bool = host is not None and host in settings.CMS_HOSTNAME_ALTERNATIVES.values()
cache_key = f"cms-{swap_domains}-{SITE_ROOT_PATHS_CACHE_KEY}"
cache_key = f"cms-{swap_domains}-{default_site_only}-{SITE_ROOT_PATHS_CACHE_KEY}"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I augmented the cache key so that if you change the setting, you don't need to flush Redis.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very nice!

@MaciekBaron MaciekBaron added the Bug Fix Something isn't working label Mar 25, 2026
@sanjeevz3009 sanjeevz3009 self-requested a review March 25, 2026 12:42
Copy link
Copy Markdown
Contributor

@sanjeevz3009 sanjeevz3009 left a comment

Choose a reason for hiding this comment

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

Tested it locally, works well! Thanks, @MaciekBaron

Comment thread cms/locale/utils.py
)
)
if default_site_only:
root_url = getattr(settings, "WAGTAILADMIN_BASE_URL", site.root_url)
Copy link
Copy Markdown
Contributor

@MebinAbraham MebinAbraham Mar 25, 2026

Choose a reason for hiding this comment

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

Q: Why do we need to do this instead of using the default site’s root_url, can you have multiple default?

If we move away from using subdomains, the “Live” button in the admin will fall back to the admin-facing URL rather than the public site hostname.

In our setup, that’s a problem because we run separate internal and external instances. The admin sits on the internal side, but the live site is served from the external hostname.

So without this change, the “Live” button would point to the internal/admin URL instead of the correct public-facing one. It’s a subtle side effect of the dual-instance architecture rather than a general Wagtail behaviour.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah right, in that case my solution wouldn't work for that scenario.

Might need to sadly close this PR then.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Noooo, I quite liked it. But I understand that in the future, when we move away from subdomains to path-based, then this change will have a negative effect ☹️

Copy link
Copy Markdown
Contributor

@MebinAbraham MebinAbraham Mar 25, 2026

Choose a reason for hiding this comment

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

If default_site_only, why not just use site.root_url, as you can only have 1 default site anyway and it should still solve the problem and handle the case for path-based locale fine?. What am I missing?.

@MaciekBaron MaciekBaron added On Hold ✋ Pull request is currently deprioritised and on hold, but not blocked labels Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Fix Something isn't working On Hold ✋ Pull request is currently deprioritised and on hold, but not blocked

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants