Skip to content

Commit e63dba2

Browse files
committed
fix #5028 Actually fix recursion bug when deleting authors
1 parent 9863bce commit e63dba2

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/submission/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3325,7 +3325,7 @@ def remove_author_from_article(sender, instance, **kwargs):
33253325
except ArticleAuthorOrder.DoesNotExist:
33263326
pass
33273327

3328-
if instance.article and instance.article.authors.exists():
3328+
if instance.article and instance.author in instance.article.authors.all():
33293329
instance.article.authors.remove(instance.author)
33303330

33313331

src/submission/tests/test_signals.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from unittest.mock import patch
2+
13
from django.test import TestCase
24

35
from submission.models import FrozenAuthor
@@ -40,3 +42,37 @@ def test_signal_removes_all_frozen_authors_on_clear(self):
4042
self.article.authors.add(self.account1, self.account2)
4143
self.article.authors.clear()
4244
self.assertFalse(FrozenAuthor.objects.filter(article=self.article).exists())
45+
46+
47+
class TestRemoveAuthorFromArticleSignal(TestCase):
48+
@classmethod
49+
def setUpTestData(cls):
50+
cls.journal, _ = helpers.create_journals()
51+
cls.article = helpers.create_article(title="Test Article", journal=cls.journal)
52+
cls.account1 = helpers.create_user(
53+
"[email protected]", ["author"], cls.journal
54+
)
55+
cls.author1 = helpers.create_frozen_author(cls.article, author=cls.account1)
56+
cls.account2 = helpers.create_user(
57+
"[email protected]", ["author"], cls.journal
58+
)
59+
cls.author2 = helpers.create_frozen_author(cls.article, author=cls.account2)
60+
cls.article.authors.add(cls.account1, cls.account2)
61+
62+
def test_signal_removes_account_from_authors_m2m(self):
63+
self.author1.delete()
64+
self.assertEqual(
65+
[self.account2],
66+
[account for account in self.article.authors.all()],
67+
)
68+
69+
@patch("submission.models.backwards_compat_authors")
70+
def test_signal_does_not_trigger_backwards_compat_if_no_m2m_authors(
71+
self, backwards_compat
72+
):
73+
account3 = helpers.create_user(
74+
"[email protected]", ["author"], self.journal
75+
)
76+
author3 = helpers.create_frozen_author(self.article, author=account3)
77+
author3.delete()
78+
backwards_compat.assert_not_called()

0 commit comments

Comments
 (0)