Skip to content

Fall back to default syndicate when site has no syndicate link - #1155

Open
ddm-j wants to merge 1 commit into
TheSpaghettiDetective:masterfrom
ddm-j:fix/syndicate-none-fallback
Open

ddm-j wants to merge 1 commit into
TheSpaghettiDetective:masterfrom
ddm-j:fix/syndicate-none-fallback

Conversation

@ddm-j

@ddm-j ddm-j commented Aug 13, 2026

Copy link
Copy Markdown

Fall back to default syndicate when site has no syndicate link

Fixes #1154

What changed

One line in syndicate_from_request() in backend/lib/syndicate.py. The anonymous-request fallback was:

return get_current_site(request).syndicates.first()

If the site isn't linked to any syndicate, that returns None and the context processor crashes on .name, which 500s every anonymous page on that host (details in the issue). Now it falls back to the default syndicate (first by id) instead - the same one the add_site_to_default_syndicate signal picks when it links newly created sites. So new sites and existing unlinked ones end up treated the same way.

Why

I hit this while sorting out #1152 on my own server. Keeping exactly one site linked to the syndicate is what makes media URLs come out with a predictable host, but before this fix, the unlinked hosts couldn't serve a login page anymore. This lets both work at once. It's a small defensive fix, nothing more.

How I tested it

  • Tests for syndicate_from_request() in backend/lib/tests.py: a linked site still resolves its own syndicate, an unlinked one resolves the default instead of None.
  • A test in backend/app/tests.py that the login page over an unlinked site's host renders 200 instead of crashing. That test class overrides STATICFILES_STORAGE to the plain storage, since the manifest storage wants a collectstatic that hasn't run in the test container.
  • All three fail without the fix, pass with it.
  • Ran the backend suite per CONTRIBUTING (docker compose -f docker-compose.yml -f docker-compose-dev.yml run --rm web python manage.py test). The 3 new tests pass. The suite also shows 33 errors in HeaterTrackerTestCase that are identical on a clean master checkout - looks like a test isolation thing (it's a TransactionTestCase, and the post-test flush deletes the default syndicate that User.syndicate defaults to). Not caused or fixed here.
  • Been running it on my production server (same one as [BUG] Changing the server domain breaks all historical timelapses, and resign_media_urls cannot repair them #1152) with one linked site and two unlinked: login and admin work over the unlinked hosts, the linked host behaves exactly as before.

Notes

No migrations, no config changes. Only requests that used to crash behave differently - anything that resolved a syndicate before resolves the same one now.

In case it comes up: this doesn't remove a way to disable a host. Unlinking never actually blocked access (logged-in users kept working the whole time), and deleting the Site record just gets you a different 500. If you want to stop serving a host, that's a reverse proxy or DNS job.

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