Skip to content

Commit

Permalink
Add filtering of not declared attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail-treskin committed Dec 8, 2021
1 parent 5f026f0 commit c1756a0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cvat/apps/lambda_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def __init__(self, gateway, data):
"`{}` lambda function has non-unique labels".format(self.id),
code=status.HTTP_404_NOT_FOUND)
self.labels = labels
# mapping of labels and corresponding supported attributes
self.attributes = {item['name']: item.get('attributes', []) for item in spec}
# state of the function
self.state = data['status']['state']
# description of the function
Expand Down Expand Up @@ -144,6 +146,10 @@ def to_dict(self):
response.update({
'state': self.state
})
if self.kind is LambdaType.DETECTOR:
response.update({
'attributes': self.attributes
})

return response

Expand Down Expand Up @@ -215,6 +221,11 @@ def invoke(self, db_task, data):
for item in response:
item["label"] = mapping.get(item["label"])
response = [item for item in response if item["label"]]
# TODO: Need to add attributes mapping similar to labels.
# Currently attribute is impicitely discarded if it is not decalred as supported in function config.
if self.attributes:
for item in response:
item['attributes'] = [attr for attr in item.get("attributes", []) if attr['name'] in self.attributes[item['label']]]

return response

Expand Down

0 comments on commit c1756a0

Please sign in to comment.