Skip to content

Commit

Permalink
[FIX] tools: prevent IoT crash due to missing library
Browse files Browse the repository at this point in the history
Before this commit:
Any IoT-box syncing to a version 16 (and >) database would not be
able to start odoo service due to the `num2words` missing library.

This is in practice the fault of the IoT as this library is part
of odoo requirement. But to solve it it would need to recreate an
IoT box OS image and asking customers to re-flash their SD card
which is not convenient and time consumming.

After this commit:
Import conditionally num2words

opw-3902183

closes #165067

Signed-off-by: Pierre Masereel (pim) <pim@odoo.com>
  • Loading branch information
lse-odoo committed May 10, 2024
1 parent eca25fe commit 7d87721
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions odoo/tools/_monkeypatches.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import ast
import os
import logging
import num2words
from odoo import MIN_PY_VERSION
from .num2words_patch import Num2Word_AR_Fixed
from shutil import copyfileobj
from types import CodeType

_logger = logging.getLogger(__name__)

try:
import num2words
from .num2words_patch import Num2Word_AR_Fixed
except ImportError:
_logger.warning("num2words is not available, Arabic number to words conversion will not work")
num2words = None

from werkzeug.datastructures import FileStorage
from werkzeug.routing import Rule
from werkzeug.wrappers import Request, Response
Expand Down Expand Up @@ -72,4 +77,5 @@ def literal_eval(expr):
if MIN_PY_VERSION >= (3, 12):
raise RuntimeError("The num2words monkey patch is obsolete. Bump the version of the library to the latest available in the official package repository, if it hasn't already been done, and remove the patch.")

num2words.CONVERTER_CLASSES["ar"] = Num2Word_AR_Fixed()
if num2words:
num2words.CONVERTER_CLASSES["ar"] = Num2Word_AR_Fixed()

0 comments on commit 7d87721

Please sign in to comment.