diff --git a/fix-django41.patch b/fix-django41.patch new file mode 100644 index 0000000..7972f15 --- /dev/null +++ b/fix-django41.patch @@ -0,0 +1,67 @@ +From 94194e0f5eeacf1be2a88a28bfed62dbc6c5d5a2 Mon Sep 17 00:00:00 2001 +From: Daniel Garcia Moreno +Date: Thu, 6 Oct 2022 12:53:56 +0200 +Subject: [PATCH] Fix django4.1 compatibility issues with related fields + +In Django4.1 a ValueError exception is raised when trying to access to +foreign keys for unsaved model instances: + +https://docs.djangoproject.com/en/4.1/releases/4.1/#reverse-foreign-key-changes-for-unsaved-model-instances + +This patch ensures that everything is saved before trying to use related +models and handles the exception correctly in the Thread model pre_save. +--- + hyperkitty/models/thread.py | 8 ++++++++ + hyperkitty/tests/models/test_email.py | 6 ++++++ + 2 files changed, 14 insertions(+) + +diff --git a/hyperkitty/models/thread.py b/hyperkitty/models/thread.py +index b550cdb8..e49954a7 100644 +--- a/hyperkitty/models/thread.py ++++ b/hyperkitty/models/thread.py +@@ -148,10 +148,18 @@ class Thread(models.Model): + from .email import Email # circular import + if self.starting_email is not None: + return ++ + try: + self.starting_email = self.emails.get(parent_id__isnull=True) + except Email.DoesNotExist: + self.starting_email = self.emails.order_by("date").first() ++ except ValueError: ++ # If the Thread is not created yet, the self.emails will raise a ++ # ValueError exception. This happens at creation time because this ++ # method is called by on_pre_save ++ # ++ # https://docs.djangoproject.com/en/4.1/releases/4.1/#reverse-foreign-key-changes-for-unsaved-model-instances ++ return + + def on_pre_save(self): + self.find_starting_email() +diff --git a/hyperkitty/tests/models/test_email.py b/hyperkitty/tests/models/test_email.py +index 7bcac390..f194e2b1 100644 +--- a/hyperkitty/tests/models/test_email.py ++++ b/hyperkitty/tests/models/test_email.py +@@ -195,6 +195,9 @@ class EmailTestCase(TestCase): + subject="This is a folded\n subject", + in_reply_to="\n ", + content="Dummy message") ++ sender.save() ++ mlist.save() ++ email.save() + msg = email.as_message() + self.assertEqual(msg["Subject"], "This is a folded subject") + +@@ -210,6 +213,9 @@ class EmailTestCase(TestCase): + mailinglist=mlist, + subject="Message subject", + content="Dummy message") ++ sender.save() ++ mlist.save() ++ email.save() + msg = email.as_message() + self.assertEqual(msg['from'], '"Team: J.Q. Doe" ') + +-- +2.37.3 + diff --git a/fix-elasticsearch8.patch b/fix-elasticsearch8.patch new file mode 100644 index 0000000..3b896da --- /dev/null +++ b/fix-elasticsearch8.patch @@ -0,0 +1,34 @@ +From 0e86f9cc40bf05cb819087f1fb0ee56f43968e1b Mon Sep 17 00:00:00 2001 +From: Daniel Garcia Moreno +Date: Thu, 6 Oct 2022 14:01:54 +0200 +Subject: [PATCH] Make it compatible with elasticsearch 8.0.0 + +--- + hyperkitty/tests/views/test_search.py | 10 +++++++++- + tox.ini | 2 +- + 2 files changed, 10 insertions(+), 2 deletions(-) + +diff --git a/hyperkitty/tests/views/test_search.py b/hyperkitty/tests/views/test_search.py +index ad0e9632..cad76fe6 100644 +--- a/hyperkitty/tests/views/test_search.py ++++ b/hyperkitty/tests/views/test_search.py +@@ -211,10 +211,18 @@ class SearchViewsTestCase(SearchEnabledTestCase): + + # For elasticsearch backend + from elasticsearch import RequestError ++ from elasticsearch import VERSION ++ mayor, _minor, _p = VERSION ++ ++ search_error = "dummy parsing failure" ++ if mayor > 7: ++ class ElasticError: ++ status = search_error ++ search_error = ElasticError + + class CrashingIterator(list): + def __len__(self): +- raise RequestError(400, "dummy parsing failure", {}) ++ raise RequestError(400, search_error, {}) + query = Mock() + + with self.settings(HAYSTACK_CONNECTIONS={ diff --git a/python-HyperKitty.changes b/python-HyperKitty.changes index 2b8291b..12730c4 100644 --- a/python-HyperKitty.changes +++ b/python-HyperKitty.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Thu Oct 6 12:07:43 UTC 2022 - Daniel Garcia + +- Add fix-django41.patch to fix issues with django4.1 +- Add fix-elasticsearch8.patch to fix issues with elasticsearch 8.0.0 + ------------------------------------------------------------------- Mon Jul 4 11:02:04 UTC 2022 - Ben Greiner diff --git a/python-HyperKitty.spec b/python-HyperKitty.spec index 7f69e7a..913ab21 100644 --- a/python-HyperKitty.spec +++ b/python-HyperKitty.spec @@ -78,6 +78,10 @@ Patch3: python-HyperKitty-no-mock.patch Patch4: hyperkitty-fix-qcluster-timeout.patch # https://gitlab.com/mailman/hyperkitty/-/merge_requests/381 + https://gitlab.com/mailman/hyperkitty/-/merge_requests/449 Patch5: hyperkitty-fix-py310-tests.patch +# PATCH-FIX-UPSTREAM fix-django41.patch gl#mailman/hyperkitty#467 +Patch6: fix-django41.patch +# PATCH-FIX-UPSTREAM fix-elasticsearch8.patch gl#mailman/hyperkitty#468 +Patch7: fix-elasticsearch8.patch # BuildRequires: %{python_module django-debug-toolbar >= 2.2} BuildRequires: %{python_module isort} @@ -193,6 +197,8 @@ rsync -a example_project/* build_static_files %patch3 -p1 %patch4 -p1 %patch5 -p1 +%patch6 -p1 +%patch7 -p1 %build sed -i 's|^#!/usr/bin/env.*|#!%{__mypython}|' \