Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core
Commits: 306825b1 by Mark Sapiro at 2021-04-08T14:58:32-07:00 Fixed an attempt to stringify a missing held message. - - - - - d47128f1 by Mark Sapiro at 2021-04-08T23:00:26+00:00 Merge branch 'missing' into 'master' Fixed an attempt to stringify a missing held message. Closes #856 See merge request mailman/mailman!819 - - - - - 3 changed files: - src/mailman/docs/NEWS.rst - src/mailman/rest/post_moderation.py - src/mailman/rest/tests/test_moderation.py Changes: ===================================== src/mailman/docs/NEWS.rst ===================================== @@ -26,6 +26,11 @@ Bugs when a member's bounce score is incremented, now contain a copy of the triggering DSN. (Closes #737) +REST +---- +* Fixed an exception on retreiving held messages if the held request exists, + but the message is missing. (Closes #856) + New Features ------------ * There is a new ``bounce_notify_admin_on_bounce_increment`` list setting and ===================================== src/mailman/rest/post_moderation.py ===================================== @@ -74,7 +74,15 @@ class _HeldMessageBase(_ModerationBase): # resource. XXX See LP: #967954 key = resource.pop('key') msg = getUtility(IMessageStore).get_message_by_id(key) - resource['msg'] = msg.as_string() + if msg is None: + resource['msg'] = """\ +Subject: Message content lost +Message-ID: {} + +This held message has been lost. +""".format(key) + else: + resource['msg'] = msg.as_string() # Some of the _mod_* keys we want to rename and place into the JSON # resource. Others we can drop. Since we're mutating the dictionary, # we need to make a copy of the keys. When you port this to Python 3, ===================================== src/mailman/rest/tests/test_moderation.py ===================================== @@ -21,9 +21,11 @@ import unittest from mailman.app.lifecycle import create_list from mailman.app.moderator import hold_message +from mailman.config import config from mailman.database.transaction import transaction from mailman.interfaces.bans import IBanManager from mailman.interfaces.mailinglist import SubscriptionPolicy +from mailman.interfaces.messages import IMessageStore from mailman.interfaces.requests import IListRequests, RequestType from mailman.interfaces.subscriptions import ISubscriptionManager from mailman.interfaces.usermanager import IUserManager @@ -77,6 +79,54 @@ Something else. call_api('http://localhost:9001/3.0/lists/a...@example.com/held/99') self.assertEqual(cm.exception.code, 404) + def test_held_message_is_missing(self): + # Missing message returns appropriately. + with transaction(): + held_id = hold_message(self._mlist, self._msg) + url = 'http://localhost:9001/3.0/lists/a...@example.com/held' + json, response = call_api(url) + self.assertEqual(response.status_code, 200) + self.assertEqual(json['total_size'], 1) + self.assertEqual(json['entries'][0]['request_id'], held_id) + self.assertEqual(json['entries'][0]['msg'], """\ +From: a...@example.com +To: a...@example.com +Subject: Something +Message-ID: <alpha> +Message-ID-Hash: XZ3DGG4V37BZTTLXNUX4NABB4DNQHTCP +X-Message-ID-Hash: XZ3DGG4V37BZTTLXNUX4NABB4DNQHTCP + +Something else. +""") + # Now delete the message from the message store and try again. + getUtility(IMessageStore).delete_message('<alpha>') + config.db.commit() + json, response = call_api(url) + self.assertEqual(response.status_code, 200) + self.assertEqual(json['total_size'], 1) + self.assertEqual(json['entries'][0]['request_id'], held_id) + self.assertEqual(json['entries'][0]['msg'], """\ +Subject: Message content lost +Message-ID: <alpha> + +This held message has been lost. +""") + + def test_delete_missing_message(self): + # Ensure we can delete a held message request with a missing message. + with transaction(): + held_id = hold_message(self._mlist, self._msg) + # Now delete the message from the message store. + getUtility(IMessageStore).delete_message('<alpha>') + config.db.commit() + # There is still a request. + requests = IListRequests(self._mlist) + key, data = requests.get_request(held_id) + self.assertEqual(key, '<alpha>') + # Now delete the request. + requests.delete_request(held_id) + self.assertIsNone(requests.get_request(held_id)) + def test_request_is_not_held_message(self): requests = IListRequests(self._mlist) with transaction(): View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/ca0f7c164f950e7ea64a00868f6bf0196fa0231f...d47128f11a20daeb4a8b488024f197379c3b9aeb -- View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/ca0f7c164f950e7ea64a00868f6bf0196fa0231f...d47128f11a20daeb4a8b488024f197379c3b9aeb You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list -- mailman-checkins@python.org To unsubscribe send an email to mailman-checkins-le...@python.org https://mail.python.org/mailman3/lists/mailman-checkins.python.org/ Member address: arch...@jab.org