Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 23, 2024

Conversation

alexis-via
Copy link
Contributor

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
Copy link
Contributor

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

Copy link

@LaetitiaElabore LaetitiaElabore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested just now : the bug is fixed

@nilshamerlinck
Copy link
Contributor

interesting plot twist to see pypdf active again!

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

Switch from PyPDF2 (deprecated) to pypdf (actively maintained)
@alexis-via alexis-via force-pushed the 14-fix-crash_mimetypes branch from 8a40734 to 89423e0 Compare May 23, 2024 10:39
@alexis-via
Copy link
Contributor Author

@nilshamerlinck I took into account your suggestion

@alexis-via
Copy link
Contributor Author

/ocabot merge major

@OCA-git-bot
Copy link
Contributor

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 OCA-git-bot merged commit 59519ab into OCA:14.0 May 23, 2024
6 of 7 checks passed
@OCA-git-bot
Copy link
Contributor

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

@etobella
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants