From a5415104170b880037b3efcb5148b85d75c551ac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A6var=20=C3=96fj=C3=B6r=C3=B0=20Magn=C3=BAsson?=
 <saevar@overcast.is>
Date: Tue, 3 Nov 2020 23:42:39 +0000
Subject: [PATCH] Additional safeguard to check if a cached site is from an
 older version of Wagtail (#6515)

---
 CHANGELOG.txt            | 2 +-
 docs/releases/2.11.1.rst | 2 +-
 wagtail/core/models.py   | 6 +++++-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index e19740fa9d..c95e4ec104 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -10,7 +10,7 @@ Changelog
 2.11.1 (xx.xx.xxxx) - IN DEVELOPMENT
 ~~~~~~~~~~~~~~~~~~~
 
- * ...
+ * Fix: Ensure that cached `wagtail_site_root_paths` structures from older Wagtail versions are invalidated (Sævar Öfjörð Magnússon)
 
 
 2.11 LTS (02.11.2020)
diff --git a/docs/releases/2.11.1.rst b/docs/releases/2.11.1.rst
index f835fa2eaa..5f031e50e4 100644
--- a/docs/releases/2.11.1.rst
+++ b/docs/releases/2.11.1.rst
@@ -13,4 +13,4 @@ What's new
 Bug fixes
 ~~~~~~~~~
 
- * ...
+ * Ensure that cached ``wagtail_site_root_paths`` structures from older Wagtail versions are invalidated (Sævar Öfjörð Magnússon)
diff --git a/wagtail/core/models.py b/wagtail/core/models.py
index 4688023a9e..17a5f2d48c 100644
--- a/wagtail/core/models.py
+++ b/wagtail/core/models.py
@@ -299,7 +299,11 @@ class Site(models.Model):
         """
         result = cache.get('wagtail_site_root_paths')
 
-        if result is None:
+        # Wagtail 2.11 changed the way site root paths were stored. This can cause an upgraded 2.11
+        # site to break when loading cached site root paths that were cached with 2.10.2 or older
+        # versions of Wagtail. The line below checks if the any of the cached site urls is consistent
+        # with an older version of Wagtail and invalidates the cache.
+        if result is None or any(len(site_record) == 3 for site_record in result):
             result = []
 
             for site in Site.objects.select_related('root_page', 'root_page__locale').order_by('-root_page__url_path', '-is_default_site', 'hostname'):