summaryrefslogtreecommitdiff
path: root/odoo/tools
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2020-12-08 13:52:14 +0000
committerXavier Morel <xmo@odoo.com>2020-12-08 13:52:14 +0000
commitc36aa16c2cc431a1e3b3bb7047dbae4fcac13946 (patch)
treeb6d6817bf948980772a3320e5da2bfb595b59d58 /odoo/tools
parent28c3d671fe2d140ff4d412d4010537e94eb39b91 (diff)
[FIX] core: don't require xlrd
Despite being part of the requirement.txt, xlrd apparently was still optional-ish, and absent from some environments like the iotbox. Restore this by only monkeypatching xlrd if it's actually present. closes odoo/odoo#63025 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Diffstat (limited to 'odoo/tools')
-rw-r--r--odoo/tools/_monkeypatches.py33
1 files changed, 18 insertions, 15 deletions
diff --git a/odoo/tools/_monkeypatches.py b/odoo/tools/_monkeypatches.py
index ce8ba4987e2..d6a604783ef 100644
--- a/odoo/tools/_monkeypatches.py
+++ b/odoo/tools/_monkeypatches.py
@@ -1,15 +1,18 @@
-from xlrd import xlsx
-from lxml import etree
-
-# xlrd.xlsx supports defusedxml, defusedxml's etree interface is broken
-# (missing ElementTree and thus ElementTree.iter) which causes a fallback to
-# Element.getiterator(), triggering a warning before 3.9 and an error from 3.9.
-#
-# We have defusedxml installed because zeep has a hard dep on defused and
-# doesn't want to drop it (mvantellingen/python-zeep#1014).
-#
-# Ignore the check and set the relevant flags directly using lxml as we have a
-# hard dependency on it.
-xlsx.ET = etree
-xlsx.ET_has_iterparse = True
-xlsx.Element_has_iter = True
+try:
+ from xlrd import xlsx
+except ImportError:
+ pass
+else:
+ from lxml import etree
+ # xlrd.xlsx supports defusedxml, defusedxml's etree interface is broken
+ # (missing ElementTree and thus ElementTree.iter) which causes a fallback to
+ # Element.getiterator(), triggering a warning before 3.9 and an error from 3.9.
+ #
+ # We have defusedxml installed because zeep has a hard dep on defused and
+ # doesn't want to drop it (mvantellingen/python-zeep#1014).
+ #
+ # Ignore the check and set the relevant flags directly using lxml as we have a
+ # hard dependency on it.
+ xlsx.ET = etree
+ xlsx.ET_has_iterparse = True
+ xlsx.Element_has_iter = True