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: NEW
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:
Keywords:
Depends on:
Blocks: Macro-Python
  Show dependency treegraph
 
Reported: 2020-05-17 14:56 UTC by Jan
Modified: 2020-11-22 13:22 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
I can reproduce this with the following steps:
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.