Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed server for duplicate attribute names #7890

Merged
merged 7 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- server checks attributes with duplicate names and throws ValidationError if found
KrishavRajSingh marked this conversation as resolved.
Show resolved Hide resolved
(<https://github.com/cvat-ai/cvat/pull/7890>)
9 changes: 8 additions & 1 deletion cvat/apps/engine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2282,7 +2282,14 @@ def perform_update(self, serializer):
"Sublabels cannot be modified this way. "
"Please send a PATCH request with updated parent label data instead.",
code=status.HTTP_400_BAD_REQUEST)

attributes = self.request.data.get('attributes')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need not only run this validation when updating a Label, but also when creating it.

Please, move this logic to the LabelSerializer (there are methods update_label and create_labels).
These methods are called from ProjectWriteSerializer and TaskWriteSerializer when labels updated.

encountered_names = set()
for attribute in attributes:
attr_name = attribute.get('name')
if attr_name in encountered_names:
raise ValidationError('attribute with same name exists')
else:
encountered_names.add(attr_name)
return super().perform_update(serializer)

def perform_destroy(self, instance: models.Label):
Expand Down