Skip to content

Commit

Permalink
fix: don't include logos from deleted images in additional routes
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Nov 7, 2023
1 parent ab4c4ac commit 4b7e130
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion robotoff/app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 20 additions & 1 deletion robotoff/app/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4b7e130

Please sign in to comment.