From bdceb080a9ee946a347f7e3895d6f62d91bcb7b3 Mon Sep 17 00:00:00 2001 From: Sanket Brahmbhatt Date: Tue, 11 Jul 2023 13:05:12 +0000 Subject: [PATCH] [FIX] account: adopt unexpected string while upload This issue occurs while uploading a PDF file and that PDF file has an unexpected string. So, The trackback will appear. Step reproduce : - install the account_accountant Module - Open Accounting Module - Click On Customer > Invoices - Click On Upload Button > Upload PDF file Error: Unexpected escaped string: b'~' When a user uploads a PDF file, PyPDF2 does not recognise the symbol and character combination as a valid escape sequence, such as (\), (~). sentry-4304111635 closes odoo/odoo#129556 X-original-commit: ea150a6f4be44ffc6f15837d5febd06fa1b695be Signed-off-by: John Laterre (jol) --- addons/account/models/ir_attachment.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/account/models/ir_attachment.py b/addons/account/models/ir_attachment.py index 1b428b2d262..7887a7b0c69 100644 --- a/addons/account/models/ir_attachment.py +++ b/addons/account/models/ir_attachment.py @@ -4,6 +4,7 @@ from odoo.tools.pdf import OdooPdfFileReader from lxml import etree from struct import error as StructError +from PyPDF2.utils import PdfReadError import io import logging @@ -57,7 +58,7 @@ class IrAttachment(models.Model): try: for xml_name, xml_content in pdf_reader.getAttachments(): to_process.extend(self._decode_edi_xml(xml_name, xml_content)) - except (NotImplementedError, StructError) as e: + except (NotImplementedError, StructError, PdfReadError) as e: _logger.warning("Unable to access the attachments of %s. Tried to decrypt it, but %s.", filename, e) # Process the pdf itself.