@@ -131,8 +131,8 @@ def optimize() -> Tuple[str, http.HTTPStatus]:
131131 'condition_optimizer_config_override' :
132132 flask .request .headers .get ('condition_optimizer_config_override' , '' ),
133133 'free_shipping_optimizer_config_override' :
134- flask .request .headers .get (
135- 'free_shipping_optimizer_config_override' , '' ),
134+ flask .request .headers .get ('free_shipping_optimizer_config_override' ,
135+ '' ),
136136 'gender_optimizer_config_override' :
137137 flask .request .headers .get ('gender_optimizer_config_override' , '' ),
138138 'promo_text_removal_optimizer_config_override' :
@@ -163,6 +163,8 @@ def optimize() -> Tuple[str, http.HTTPStatus]:
163163
164164 product_batch = flask .request .json
165165
166+ _sanitize_batch (product_batch )
167+
166168 optimized_product_batch , builtin_optimizer_results = _run_optimizers (
167169 product_batch , lang_url_parameter , country_url_parameter ,
168170 currency_url_parameter , _builtin_optimizer_cache )
@@ -240,6 +242,18 @@ def _check_request_valid(lang_url_parameter: str) -> (bool, str):
240242 return True , ''
241243
242244
245+ def _sanitize_batch (product_batch : Dict [str , Any ]) -> None :
246+ """Cleans up the product batch.
247+
248+ Args:
249+ product_batch: A batch of product data.
250+ """
251+ for entry in product_batch ['entries' ]:
252+ product = entry ['product' ]
253+ for attribute in ('title' , 'description' ):
254+ product [attribute ] = str (product .get (attribute , '' ))
255+
256+
243257def _run_optimizers (
244258 product_batch : Dict [str , Any ],
245259 language : str ,
0 commit comments