From 9a709abb7d2db36254922ed4d069867c56fdcdfe Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Wed, 18 Mar 2026 14:48:10 -0700 Subject: [PATCH] Fix(parsers): pop legacy constructor args in mail signal wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MailDocumentParser.__init__ takes no constructor args in the new protocol. Update the get_parser() signal wrapper to pop logging_group and progress_callback (passed by the legacy consumer dispatch path) before instantiating — the same pattern used by TextDocumentParser. Also update test_mail_parser_receives_mailrule to use the real signal wrapper (mail_get_parser) instead of MailDocumentParser directly, so the test exercises the actual dispatch path and matches the new parse() call signature (no mailrule kwarg). Co-Authored-By: Claude Sonnet 4.6 --- src/documents/tests/test_consumer.py | 15 +++++++-------- src/paperless_mail/signals.py | 7 ++++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/documents/tests/test_consumer.py b/src/documents/tests/test_consumer.py index 006a61b07..a3574fdce 100644 --- a/src/documents/tests/test_consumer.py +++ b/src/documents/tests/test_consumer.py @@ -35,7 +35,6 @@ from documents.tests.utils import DirectoriesMixin from documents.tests.utils import DummyProgressManager from documents.tests.utils import FileSystemAssertsMixin from documents.tests.utils import GetConsumerMixin -from paperless.parsers.mail import MailDocumentParser from paperless_mail.models import MailRule @@ -1107,11 +1106,13 @@ class TestConsumer( THEN: - The mail parser should receive the mail rule """ + from paperless_mail.signals import get_parser as mail_get_parser + mock_consumer_declaration_send.return_value = [ ( None, { - "parser": MailDocumentParser, + "parser": mail_get_parser, "mime_types": {"message/rfc822": ".eml"}, "weight": 0, }, @@ -1137,12 +1138,10 @@ class TestConsumer( ConsumerError, ): consumer.run() - mock_mail_parser_parse.assert_called_once_with( - consumer.working_copy, - "message/rfc822", - file_name="sample.pdf", - mailrule=mock_mailrule_get.return_value, - ) + mock_mail_parser_parse.assert_called_once_with( + consumer.working_copy, + "message/rfc822", + ) @mock.patch("documents.consumer.magic.from_file", fake_magic_from_file) diff --git a/src/paperless_mail/signals.py b/src/paperless_mail/signals.py index 70b3f56e4..8fe046393 100644 --- a/src/paperless_mail/signals.py +++ b/src/paperless_mail/signals.py @@ -1,7 +1,12 @@ def get_parser(*args, **kwargs): from paperless.parsers.mail import MailDocumentParser - return MailDocumentParser(*args, **kwargs) + # MailDocumentParser accepts no constructor args in the new-style protocol. + # Pop legacy args that arrive from the signal-based consumer path. + # Phase 4 will replace this signal path with the ParserRegistry. + kwargs.pop("logging_group", None) + kwargs.pop("progress_callback", None) + return MailDocumentParser() def mail_consumer_declaration(sender, **kwargs):