From 4b7e1300853bf14483a9833c9746178596db7ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Bournhonesque?= Date: Tue, 7 Nov 2023 14:46:33 +0100 Subject: [PATCH] fix: don't include logos from deleted images in additional routes --- robotoff/app/api.py | 6 +++++- robotoff/app/core.py | 21 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/robotoff/app/api.py b/robotoff/app/api.py index ea8e33623e..995b81c2bb 100644 --- a/robotoff/app/api.py +++ b/robotoff/app/api.py @@ -851,7 +851,11 @@ def on_get(self, req: falcon.Request, resp: falcon.Response): LogoAnnotation.select() .join(ImagePrediction) .join(ImageModel) - .where(LogoAnnotation.id.in_(logo_ids)) + .where( + LogoAnnotation.id.in_(logo_ids), + # Don't include logos from deleted images + ImageModel.deleted == False, # noqa + ) # noqa .iterator() ): logo_dict = logo.to_dict() diff --git a/robotoff/app/core.py b/robotoff/app/core.py index 0b55d040ad..6216f6e563 100644 --- a/robotoff/app/core.py +++ b/robotoff/app/core.py @@ -481,9 +481,28 @@ def get_logo_annotation( offset: Optional[int] = None, count: bool = False, ) -> Iterable[LogoAnnotation]: + """Return logos that fit the criteria passed as parameters. + + :param server_type: the server type (project) associated with the logos + :param barcode: the barcode of the product associated with the logos, + defaults to None (no barcode filter) + :param keep_types: the list of logo types to keep, defaults to None (no + type filter) + :param value_tag: the annotation value tag to filter on, defaults to None + (no value tag filter) + :param limit: maximum number of logos to return, defaults to 25 + :param offset: offset for pagination, defaults to None (page 1) + :param count: if True, return the number of logos instead of the logos, + defaults to False + :return: either the number of logos (if `count=True`) or an iterable of + logos + """ query = LogoAnnotation.select().join(ImagePrediction).join(ImageModel) - where_clauses = [ImageModel.server_type == server_type.name] + where_clauses = [ + ImageModel.server_type == server_type.name, + ImageModel.deleted == False, # noqa + ] if barcode: where_clauses.append(LogoAnnotation.barcode == barcode)