-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Added validation of duration
field for change:frame
#7211
Conversation
duration
field for change:frame
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## develop #7211 +/- ##
===========================================
- Coverage 81.35% 81.33% -0.02%
===========================================
Files 366 366
Lines 39357 39358 +1
Branches 3644 3645 +1
===========================================
- Hits 32017 32010 -7
- Misses 7340 7348 +8
|
cvat/apps/events/serializers.py
Outdated
def validate(self, data): | ||
for event in data["events"]: | ||
if event["scope"] in self._COLLAPSED_EVENT_SCOPES: | ||
if not isinstance(event.get("duration"), int): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something seems wrong here. EventSerializer.duration
has a default, so it should not be possible for it to be anything other than an int:
>>> s = EventSerializer(data={'scope': 'change:frame', 'timestamp': '2023-12-06T10:47:14.085178'})
>>> s.is_valid()
True
>>> s.validated_data['duration']
0
Are we skipping EventSerializer
's validation somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm.. yes, it has
default implementation for validate
in Serializer class is:
def validate(self, attrs):
return attrs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validate
only handles custom validation, so it makes sense that it does nothing by default. The per-field validation is supposed to happen somewhere inside is_valid
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, perhaps we only need to keep default value in to_internal_value
Check is not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, now it uses default value from nested class
duration
field for change:frame
duration
field for change:frame
duration
field for change:frame
duration
field for change:frame
Fix exceptions with 500 code, like this in our logging system: ``` Error: KeyError: 'duration' Error count: 131 Stack: Traceback (most recent call last): File "/opt/venv/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch response = handler(request, *args, **kwargs) File "/home/django/cvat/apps/events/views.py", line 32, in create serializer.is_valid(raise_exception=True) File "/opt/venv/lib/python3.10/site-packages/rest_framework/serializers.py", line 227, in is_valid self._validated_data = self.run_validation(self.initial_data) File "/opt/venv/lib/python3.10/site-packages/rest_framework/serializers.py", line 426, in run_validation value = self.to_internal_value(data) File "/home/django/cvat/apps/events/serializers.py", line 59, in to_internal_value event_duration += datetime.timedelta(milliseconds=event["duration"]) KeyError: 'duration' ```
Motivation and context
Fix exceptions with 500 code, like this in our logging system:
How has this been tested?
Checklist
develop
branch(cvat-canvas,
cvat-core,
cvat-data and
cvat-ui)
License
Feel free to contact the maintainers if that's a concern.