Skip to content

Commit

Permalink
Checks for frame_selection_method if honeypot_real_frames specified
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiltsov-max committed Oct 3, 2024
1 parent 7bb5ae7 commit 0123148
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
30 changes: 21 additions & 9 deletions cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ class JobWriteSerializer(WriteOnceMixin, serializers.ModelSerializer):
frames = serializers.ListField(
child=serializers.IntegerField(min_value=0),
required=False,
allow_empty=False,
help_text=textwrap.dedent("""\
The list of frame ids. Applicable only to the "{}" frame selection method
""".format(models.JobFrameSelectionMethod.MANUAL))
Expand Down Expand Up @@ -734,13 +735,9 @@ def validate(self, attrs):
elif frame_selection_method == models.JobFrameSelectionMethod.MANUAL:
field_validation.require_field(attrs, "frames")

frames = attrs['frames']
if not frames:
raise serializers.ValidationError("The list of frames cannot be empty")

if (
frame_selection_method != models.JobFrameSelectionMethod.MANUAL and
attrs.get('frames')
'frames' in attrs and
frame_selection_method != models.JobFrameSelectionMethod.MANUAL
):
raise serializers.ValidationError(
'"frames" can only be used when "frame_selection_method" is "{}"'.format(
Expand Down Expand Up @@ -942,8 +939,8 @@ class JobValidationLayoutWriteSerializer(serializers.Serializer):
)
honeypot_real_frames = serializers.ListSerializer(
child=serializers.IntegerField(min_value=0),
default=[],
required=False,
allow_empty=False,
help_text=textwrap.dedent("""\
The list of frame ids. Applicable only to the "{}" frame selection method
""".format(models.JobFrameSelectionMethod.MANUAL))
Expand All @@ -958,6 +955,15 @@ def validate(self, attrs):
else:
assert False

if (
'honeypot_real_frames' in attrs and
frame_selection_method != models.JobFrameSelectionMethod.MANUAL
):
raise serializers.ValidationError(
'"honeypot_real_frames" can only be used when '
f'"frame_selection_method" is "{models.JobFrameSelectionMethod.MANUAL}"'
)

return super().validate(attrs)

@transaction.atomic
Expand Down Expand Up @@ -1258,8 +1264,14 @@ def validate(self, attrs):
elif frame_selection_method == models.JobFrameSelectionMethod.RANDOM_UNIFORM:
pass

if "honeypot_real_frames" in attrs:
field_validation.require_field(attrs, "frame_selection_method")
if (
'honeypot_real_frames' in attrs and
frame_selection_method != models.JobFrameSelectionMethod.MANUAL
):
raise serializers.ValidationError(
'"honeypot_real_frames" can only be used when '
f'"frame_selection_method" is "{models.JobFrameSelectionMethod.MANUAL}"'
)

return super().validate(attrs)

Expand Down
1 change: 0 additions & 1 deletion cvat/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9424,7 +9424,6 @@ components:
items:
type: integer
minimum: 0
default: []
description: |
The list of frame ids. Applicable only to the "manual" frame selection method
PatchedJobWriteRequest:
Expand Down

0 comments on commit 0123148

Please sign in to comment.