Bug 133123 - Python module uno.py overrides import, resulting in failure of subsequent import cairosvg module
Summary: Python module uno.py overrides import, resulting in failure of subsequent imp...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
6.4.3.2 release
Hardware: All Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:7.5.0 target:7.4.1
Keywords:
Depends on:
Blocks: Macro-Python
  Show dependency treegraph
 
Reported: 2020-05-17 14:56 UTC by Jan
Modified: 2024-10-11 22:12 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan 2020-05-17 14:56:42 UTC
Description:
Python module uno.py overrides import. And that overwritten function fails to import some modules. Cairosvg is one example.
Workaround is to import carirosvg before libreoffice ones.
It looks like sys.modules can contain entry for module with value None. Maybe simple check against that would work. Or maybe there is needed other approach with Python 3.8?

Steps to Reproduce:
Simle code like:
import uno
import cairosvg

After failure it looks like sys.modules["_elementtree"] is None.
(Key exists in that dict, but with None as value)

Actual Results:
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    import cairosvg
  File "/usr/lib64/python3.8/site-packages/uno.py", line 359, in _uno_import
    return _builtin_import(name, *optargs, **kwargs)
  File "/usr/lib/python3.8/site-packages/cairosvg/__init__.py", line 42, in <module>
    from . import surface  # noqa isort:skip
  File "/usr/lib64/python3.8/site-packages/uno.py", line 359, in _uno_import
    return _builtin_import(name, *optargs, **kwargs)
  File "/usr/lib/python3.8/site-packages/cairosvg/surface.py", line 28, in <module>
    from .defs import (
  File "/usr/lib64/python3.8/site-packages/uno.py", line 359, in _uno_import
    return _builtin_import(name, *optargs, **kwargs)
  File "/usr/lib/python3.8/site-packages/cairosvg/defs.py", line 24, in <module>
    from .bounding_box import calculate_bounding_box, is_non_empty_bounding_box
  File "/usr/lib64/python3.8/site-packages/uno.py", line 359, in _uno_import
    return _builtin_import(name, *optargs, **kwargs)
  File "/usr/lib/python3.8/site-packages/cairosvg/bounding_box.py", line 28, in <module>
    from .parser import Tree
  File "/usr/lib64/python3.8/site-packages/uno.py", line 359, in _uno_import
    return _builtin_import(name, *optargs, **kwargs)
  File "/usr/lib/python3.8/site-packages/cairosvg/parser.py", line 28, in <module>
    from defusedxml import ElementTree
  File "/usr/lib64/python3.8/site-packages/uno.py", line 359, in _uno_import
    return _builtin_import(name, *optargs, **kwargs)
  File "/usr/lib/python3.8/site-packages/defusedxml/ElementTree.py", line 63, in <module>
    _XMLParser, _iterparse, ParseError = _get_py3_cls()
  File "/usr/lib/python3.8/site-packages/defusedxml/ElementTree.py", line 48, in _get_py3_cls
    pure_pymod = importlib.import_module(pymodname)
  File "/usr/lib64/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/lib64/python3.8/xml/etree/ElementTree.py", line 2053, in <module>
    from _elementtree import *
  File "/usr/lib64/python3.8/site-packages/uno.py", line 383, in _uno_import
    d = mod.__dict__
AttributeError: 'NoneType' object has no attribute '__dict__'


Expected Results:
Proper import of cairosvg, with modules it imports. 
Workaround is to use:
import cairosvg
import uno


Reproducible: Always


User Profile Reset: Yes



Additional Info:
Python 3.8.2
libreoffice-pyuno-6.4.3.2-1.fc32.x86_64
Comment 1 Kevin Suo 2020-10-23 08:59:59 UTC Comment hidden (obsolete)
Comment 2 Kevin Suo 2020-10-23 09:09:37 UTC
I can reproduce this bug with the following steps:

1. Install cairosvg with pip.

2. start ipython interactive console:
> $ PYTHONPATH=/home/suokunlong/build/lo/master/instdir/program/ ipython3

3. Import cairosvg before importing uno:

> In [1]: import cairosvg                                                         
> In [2]: import uno
> In [4]: sys.modules["_elementtree"]                                             
> Out[4]: <module '_elementtree' from '/usr/lib64/python3.8/lib-dynload/_elementtree.cpython-38-x86_64-linux-gnu.so'>

4. Import cairosvg after importing uno:

> In [1]: import uno
> In [2]: import cairosvg
> AttributeError: 'NoneType' object has no attribute '__dict__'
> In [3]: import sys                                                              
> In [4]: sys.modules["_elementtree"]
> (None)

Fedora 32, master build as of today.
Comment 3 Commit Notification 2022-08-09 09:56:10 UTC
Niko Fink committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/1052ec9cff72e2810fdb934a85ab500d3b4ace35

tdf#133123: fix crash when importing defusedxml.ElementTree after pyuno

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 4 Commit Notification 2022-08-09 13:36:24 UTC
Niko Fink committed a patch related to this issue.
It has been pushed to "libreoffice-7-4":

https://git.libreoffice.org/core/commit/cd048ca7ab61718586f7ef5b48dccbb6bd38299c

tdf#133123: fix crash when importing defusedxml.ElementTree after pyuno

It will be available in 7.4.1.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 5 Werner Tietz 2022-10-11 16:33:36 UTC
the Patch committed by @Niko Fink works also for:

Version: 7.0.4.2
Build ID: 00(Build:2)
CPU threads: 4; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Raspbian package version: 1:7.0.4-4+rpi1+deb11u3
Calc: threaded
Comment 6 QA Administrators 2024-10-11 03:13:42 UTC
Dear Jan,

To make sure we're focusing on the bugs that affect our users today, LibreOffice QA is asking bug reporters and confirmers to retest open, confirmed bugs which have not been touched for over a year.

There have been thousands of bug fixes and commits since anyone checked on this bug report. During that time, it's possible that the bug has been fixed, or the details of the problem have changed. We'd really appreciate your help in getting confirmation that the bug is still present.

If you have time, please do the following:

Test to see if the bug is still present with the latest version of LibreOffice from https://www.libreoffice.org/download/

If the bug is present, please leave a comment that includes the information from Help - About LibreOffice.
 
If the bug is NOT present, please set the bug's Status field to RESOLVED-WORKSFORME and leave a comment that includes the information from Help - About LibreOffice.

Please DO NOT

Update the version field
Reply via email (please reply directly on the bug tracker)
Set the bug's Status field to RESOLVED - FIXED (this status has a particular meaning that is not 
appropriate in this case)


If you want to do more to help you can test to see if your issue is a REGRESSION. To do so:
1. Download and install oldest version of LibreOffice (usually 3.3 unless your bug pertains to a feature added after 3.3) from https://downloadarchive.documentfoundation.org/libreoffice/old/

2. Test your bug
3. Leave a comment with your results.
4a. If the bug was present with 3.3 - set version to 'inherited from OOo';
4b. If the bug was not present in 3.3 - add 'regression' to keyword


Feel free to come ask questions or to say hello in our QA chat: https://web.libera.chat/?settings=#libreoffice-qa

Thank you for helping us make LibreOffice even better for everyone!

Warm Regards,
QA Team

MassPing-UntouchedBug