summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2026-06-08 11:30:59 -0400
committerJacob Walls <jacobtylerwalls@gmail.com>2026-06-08 13:04:01 -0400
commit59a89d1008ab9220275fbdcff2a44d9bbd920032 (patch)
tree08e66a9dadfc1d61b4b27ad0590020efb8bc9380
parenta7a57a21a8cf42ecc767c204f7939ad4419ae25f (diff)
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.
-rw-r--r--tests/admin_views/test_multidb.py6
1 files changed, 6 insertions, 0 deletions
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")