[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) <lse@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user