From 88213dfbbd16596a90708f9c819db5c494d437a7 Mon Sep 17 00:00:00 2001 From: "Loan (LSE)" Date: Tue, 12 Dec 2023 15:40:22 +0100 Subject: [PATCH] [FIX] product_image: handle read timeout According to: https://requests.readthedocs.io/en/stable/user/advanced/#timeouts There is 2 different timeout, the connect and read one. Both have their own exception if they timeout, the connect one was handled but not the read one. Before this commit: If the read timeout happen, a traceback will occur interrupting the (scheduled) job: File ".../odoo/addons/product_images/wizard/product_fetch_image_wizard.py", line 308, in _get_image_from_url response = self._session.get(url, timeout=5) ... requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='...', port=443): Read timed out. (read timeout=5) After this commit: We ignore the timeout-ing request the same way the request.ConnectionError do opw-3546601 closes odoo/odoo#147012 X-original-commit: a4c382e3e03541d5db7fd7c627b78658573732a4 Signed-off-by: Loan Sens (lse) --- addons/product_images/wizard/product_fetch_image_wizard.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/product_images/wizard/product_fetch_image_wizard.py b/addons/product_images/wizard/product_fetch_image_wizard.py index a2d3360b50b..abf0cf01b8f 100644 --- a/addons/product_images/wizard/product_fetch_image_wizard.py +++ b/addons/product_images/wizard/product_fetch_image_wizard.py @@ -5,7 +5,7 @@ import logging from datetime import timedelta import requests -from requests.exceptions import ConnectionError as RequestConnectionError +from requests.exceptions import ConnectionError as RequestConnectionError, Timeout as RequestTimeout from odoo import _, api, fields, models from odoo.exceptions import UserError @@ -232,7 +232,7 @@ class ProductFetchImageWizard(models.TransientModel): raise UserError(_( "Your API Key or your Search Engine ID is incorrect." )) - except (RequestConnectionError): + except (RequestConnectionError, RequestTimeout): nb_timeouts += 1 if nb_timeouts <= 3: # Temporary loss of service continue # Let the image of this product be fetched by the next cron run @@ -258,6 +258,7 @@ class ProductFetchImageWizard(models.TransientModel): break # Stop at the first valid image except ( RequestConnectionError, + RequestTimeout, UserError, # Raised when the image couldn't be decoded as base64 ): pass # Move on to the next image