From 59a89d1008ab9220275fbdcff2a44d9bbd920032 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Mon, 8 Jun 2026 11:30:59 -0400 Subject: Refs #16281 -- Fixed isolation of admin_views.ViewOnSiteTests. We were seeing this occasional failure in FlatpagesSitemapTests.setUpClass(), which was unexpectedly attempting a write on the "other" database because of an instance hint from a cached Site: django.test.testcases.DatabaseOperationForbidden: Database queries to 'other' are not allowed in this test. Add 'other' to flatpages_tests.test_sitemaps.FlatpagesSitemapTests.databases to ensure proper test isolation and silence this failure. --- tests/admin_views/test_multidb.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/admin_views/test_multidb.py b/tests/admin_views/test_multidb.py index 0f18aeb315..870d434b02 100644 --- a/tests/admin_views/test_multidb.py +++ b/tests/admin_views/test_multidb.py @@ -3,6 +3,7 @@ from unittest import mock from django.contrib import admin from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType +from django.contrib.sites.models import Site from django.http import HttpResponse from django.test import TestCase, override_settings from django.urls import path, reverse @@ -193,6 +194,11 @@ class ViewOnSiteRouter: class ViewOnSiteTests(TestCase): databases = {"default", "other"} + def tearDown(self): + # Reads via ViewOnSiteRouter may prime the global SITE_CACHE using the + # "other" db, which is problematic for other tests that do not use it. + Site.objects.clear_cache() + def test_contenttype_in_separate_db(self): ContentType.objects.using("other").all().delete() book = Book.objects.using("other").create(name="other book") -- cgit v1.3