Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions robotoff/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ def delete_images(product_id: ProductIdentifier, image_ids: list[str]):
:param image_ids: a list of image IDs to delete.
Each image ID must be a digit.
"""

if not product_id.is_valid():
logger.warning("Could not delete images, invalid product identifier")
return

server_type = product_id.server_type.name
# Perform batching as we don't know the number of images to delete
updated_models = []
Expand Down
3 changes: 3 additions & 0 deletions robotoff/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ def __repr__(self) -> str:
def __hash__(self) -> int:
return hash((self.barcode, self.server_type))

def is_valid(self) -> bool:
return bool(self.barcode and self.server_type)


@enum.unique
class ElasticSearchIndex(str, enum.Enum):
Expand Down
5 changes: 5 additions & 0 deletions robotoff/workers/tasks/product_updated.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def update_insights_job(product_id: ProductIdentifier, diffs: JSONType) -> None:
"""
logger.info("Running `update_insights` for %s", product_id)

# Check for valid product identifier
if not product_id.is_valid():
logger.info("Invalid product identifier received, skipping product update")
return

try:
with Lock(
name=f"robotoff:product_update_job:{product_id.server_type.name}:{product_id.barcode}",
Expand Down