changeset 6265d3cbb702 in modules/web_shop_vue_storefront:default
details:
https://hg.tryton.org/modules/web_shop_vue_storefront?cmd=changeset;node=6265d3cbb702
description:
Prevent NotFoundError when deleting entry
An entry may be deleted before having the chance to be indexed first.
issue9848
review349231002
diffstat:
web.py | 41 +++++++++++++++++++++++++++--------------
1 files changed, 27 insertions(+), 14 deletions(-)
diffs (70 lines):
diff -r 9c1687d29256 -r 6265d3cbb702 web.py
--- a/web.py Tue Jan 05 23:34:24 2021 +0100
+++ b/web.py Mon Jan 18 23:27:47 2021 +0100
@@ -2,6 +2,7 @@
# this repository contains the full copyright notices and license terms.
from functools import wraps
+import elasticsearch
from elasticsearch import Elasticsearch, VERSION as ES_VERSION
from trytond.exceptions import RateLimitException
@@ -197,32 +198,44 @@
if template.vsf_identifier:
template_products = product.template.get_vsf_products(shop)
if not template_products:
+ try:
+ es.delete(
+ index=shop.vsf_elasticsearch_index,
+ doc_type='product',
+ id=template.vsf_identifier.id)
+ except elasticsearch.exceptions.NotFoundError:
+ pass
+ if product.vsf_identifier:
+ try:
es.delete(
index=shop.vsf_elasticsearch_index,
doc_type='product',
- id=template.vsf_identifier.id)
- if product.vsf_identifier:
- es.delete(
- index=shop.vsf_elasticsearch_index,
- doc_type='product',
- id=product.vsf_identifier.id)
+ id=product.vsf_identifier.id)
+ except elasticsearch.exceptions.NotFoundError:
+ pass
shop.products_removed = []
for category in shop.categories_removed:
if category.vsf_identifier:
- es.delete(
- index=shop.vsf_elasticsearch_index,
- doc_type='category',
- id=category.vsf_identifier.id)
+ try:
+ es.delete(
+ index=shop.vsf_elasticsearch_index,
+ doc_type='category',
+ id=category.vsf_identifier.id)
+ except elasticsearch.exceptions.NotFoundError:
+ pass
shop.categories_removed = []
if ProductAttribute:
for attribute in shop.attributes_removed:
if attribute.vsf_identifier:
- es.delete(
- index=shop.vsf_elasticsearch_index,
- doc_type='attribute',
- id=attribute.vsf_identifier.id)
+ try:
+ es.delete(
+ index=shop.vsf_elasticsearch_index,
+ doc_type='attribute',
+ id=attribute.vsf_identifier.id)
+ except elasticsearch.exceptions.NotFoundError:
+ pass
shop.attributes_removed = []
cls.save(shops)