OCA / edi

GNU Affero General Public License v3.0
116 stars 299 forks source link

[14.0][FIX] pdf_helper: fix crash in PDF parsing and PyPDF2 -> pypdf #976

Closed alexis-via closed 1 month ago

alexis-via commented 2 months ago

Switch from PyPDF2 (deprecated) to pypdf (actively maintained)

Fix crash when importing a factur-x file:


Traceback (most recent call last):
  File "/home/alexis/new_boite/dev/14/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
    result = request.dispatch()
  File "/home/alexis/new_boite/dev/14/odoo/odoo/http.py", line 696, in dispatch
    result = self._call_function(**self.params)
  File "/home/alexis/new_boite/dev/14/odoo/odoo/http.py", line 370, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/alexis/new_boite/dev/14/odoo/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/alexis/new_boite/dev/14/odoo/odoo/http.py", line 358, in checked_call
    result = self.endpoint(*a, **kw)
  File "/home/alexis/new_boite/dev/14/odoo/odoo/http.py", line 919, in __call__
    return self.method(*args, **kw)
  File "/home/alexis/new_boite/dev/14/odoo/odoo/http.py", line 544, in response_wrap
    response = f(*args, **kw)
  File "/home/alexis/new_boite/dev/14/odoo/addons/web/controllers/main.py", line 1374, in call_button
    action = self._call_kw(model, method, args, kwargs)
  File "/home/alexis/new_boite/dev/14/odoo/addons/web/controllers/main.py", line 1362, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/home/alexis/new_boite/dev/14/odoo/odoo/api.py", line 406, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/home/alexis/new_boite/dev/14/odoo/odoo/api.py", line 391, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/home/alexis/new_boite/dev/14/edi/account_invoice_import/wizard/account_invoice_import.py", line 802, in import_invoice
    parsed_inv = self.get_parsed_invoice()
  File "/home/alexis/new_boite/dev/14/edi/account_invoice_import/wizard/account_invoice_import.py", line 651, in get_parsed_invoice
    return self.parse_invoice(self.invoice_file, self.invoice_filename)
  File "/home/alexis/new_boite/dev/14/edi/account_invoice_import/wizard/account_invoice_import.py", line 514, in parse_invoice
    parsed_inv = self.parse_pdf_invoice(file_data)
  File "/home/alexis/new_boite/dev/14/edi/account_invoice_import/wizard/account_invoice_import.py", line 91, in parse_pdf_invoice
    xml_files_dict = self.get_xml_files_from_pdf(file_data)
  File "/home/alexis/new_boite/dev/14/symlink/base_business_document_import/models/business_document_import.py", line 1287, in get_xml_files_from_pdf
    return self.env["pdf.helper"].pdf_get_xml_files(pdf_file)
  File "/home/alexis/new_boite/dev/14/edi/pdf_helper/models/helper.py", line 24, in pdf_get_xml_files
    return parser.get_xml_files()
  File "/home/alexis/new_boite/dev/14/edi/pdf_helper/utils.py", line 33, in get_xml_files
    xmlfiles = self._extract_xml_files(fd)
  File "/home/alexis/new_boite/dev/14/edi/pdf_helper/utils.py", line 53, in _extract_xml_files
    mime_res = mimetypes.guess_type(embeddedfile)
  File "/usr/lib/python3.10/mimetypes.py", line 307, in guess_type
    return _db.guess_type(url, strict)
  File "/usr/lib/python3.10/mimetypes.py", line 122, in guess_type
    url = os.fspath(url)
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/alexis/new_boite/dev/14/odoo/odoo/http.py", line 652, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/alexis/new_boite/dev/14/odoo/odoo/http.py", line 317, in _handle_exception
    raise exception.with_traceback(None) from new_cause
TypeError: expected str, bytes or os.PathLike object, not IndirectObject
``
OCA-git-bot commented 2 months ago

Hi @simahawk, some modules you are maintaining are being modified, check this out!

nilshamerlinck commented 1 month ago

interesting plot twist to see pypdf active again!

maybe worth adding "external_dependencies": {"python": ["pypdf"]} in the manifest?

alexis-via commented 1 month ago

@nilshamerlinck I took into account your suggestion

alexis-via commented 1 month ago

/ocabot merge major

OCA-git-bot commented 1 month ago

On my way to merge this fine PR! Prepared branch 14.0-ocabot-merge-pr-976-by-alexis-via-bump-major, awaiting test results.

OCA-git-bot commented 1 month ago

Congratulations, your PR was merged at 8975c095ea1e48a0a905c8626210d20355e70e8b. Thanks a lot for contributing to OCA. ❤️

etobella commented 1 month ago

Adding a dependency on an already merged module can give a lot of issues @alexis-via

Now I need to install this library on all my instances due to this change

Couldn't be solved without an extra library?