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

Invalid input validation in client.tasks.api.retrieve_annotations for cloud_storage_id. #6823

Closed
2 tasks done
kzvdar42 opened this issue Sep 6, 2023 · 0 comments · Fixed by #6825
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@kzvdar42
Copy link

kzvdar42 commented Sep 6, 2023

My actions before raising this issue

Steps to Reproduce (for bugs)

task_id = 1
cloud_storage_id = 1
response = cvat_client.tasks.api.retrieve_annotations(
    task_id,
    cloud_storage_id=cloud_storage_id,
    filename=f"test.zip",
    format="CVAT for images 1.1",
    location='cloud_storage',
    _parse_response=False,
    use_default_location=False,
)

Expected Behaviour

API call is performed without errors

Current Behaviour

Request fails with server error 500 (server expects integer for cloud_storage_id, but gets float)

cvat server logs
   [2023-09-06 15:03:24,452] ERROR django.request: Internal Server Error: /api/tasks/202/annotations/
Traceback (most recent call last):
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 2053, in get_prep_value
    return int(value)
ValueError: invalid literal for int() with base 10: '1.0'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/opt/venv/lib/python3.10/site-packages/asgiref/sync.py", line 534, in thread_handler
    raise exc_info[1]
  File "/opt/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 42, in inner
    response = await get_response(request)
  File "/opt/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 253, in _get_response_async
    response = await wrapped_callback(
  File "/opt/venv/lib/python3.10/site-packages/asgiref/sync.py", line 479, in __call__
    ret: _R = await loop.run_in_executor(
  File "/opt/venv/lib/python3.10/site-packages/asgiref/current_thread_executor.py", line 40, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/opt/venv/lib/python3.10/site-packages/asgiref/sync.py", line 538, in thread_handler
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
    return view_func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/opt/venv/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/opt/venv/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  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/engine/views.py", line 1297, in annotations
    self._object = self.get_object() # force call of check_object_permissions()
  File "/opt/venv/lib/python3.10/site-packages/rest_framework/generics.py", line 99, in get_object
    self.check_object_permissions(self.request, obj)
  File "/opt/venv/lib/python3.10/site-packages/rest_framework/views.py", line 345, in check_object_permissions
    if not permission.has_object_permission(request, self, obj):
  File "/home/django/cvat/apps/iam/permissions.py", line 2023, in has_object_permission
    return self.check_permission(request, view, obj)
  File "/home/django/cvat/apps/iam/permissions.py", line 2007, in check_permission
    permissions.extend(perm.create(request, view, obj, iam_context))
  File "/home/django/cvat/apps/iam/permissions.py", line 915, in create
    permissions.append(CloudStoragePermission.create_scope_view(
  File "/home/django/cvat/apps/iam/permissions.py", line 630, in create_scope_view
    obj = CloudStorage.objects.get(id=storage_id)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 623, in get
    clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1436, in filter
    return self._filter_or_exclude(False, args, kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1454, in _filter_or_exclude
    clone._filter_or_exclude_inplace(negate, args, kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1461, in _filter_or_exclude_inplace
    self._query.add_q(Q(*args, **kwargs))
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1534, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1565, in _add_q
    child_clause, needed_inner = self.build_filter(
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1480, in build_filter
    condition = self.build_lookup(lookups, col, value)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1307, in build_lookup
    lookup = lookup_class(lhs, rhs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/lookups.py", line 27, in __init__
    self.rhs = self.get_prep_lookup()
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/lookups.py", line 341, in get_prep_lookup
    return super().get_prep_lookup()
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/lookups.py", line 85, in get_prep_lookup
    return self.lhs.output_field.get_prep_value(self.rhs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 2055, in get_prep_value
    raise e.__class__(
ValueError: Field 'id' expected a number but got '1.0'.
2023-09-06 15:03:24,453 DEBG 'uvicorn-1' stderr output:
ERROR:django.request:Internal Server Error: /api/tasks/202/annotations/
Traceback (most recent call last):
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 2053, in get_prep_value
    return int(value)
ValueError: invalid literal for int() with base 10: '1.0'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/opt/venv/lib/python3.10/site-packages/asgiref/sync.py", line 534, in thread_handler
    raise exc_info[1]
  File "/opt/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 42, in inner
    response = await get_response(request)
  File "/opt/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 253, in _get_response_async
    response = await wrapped_callback(
  File "/opt/venv/lib/python3.10/site-packages/asgiref/sync.py", line 479, in __call__
    ret: _R = await loop.run_in_executor(
  File "/opt/venv/lib/python3.10/site-packages/asgiref/current_thread_executor.py", line 40, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/opt/venv/lib/python3.10/site-packages/asgiref/sync.py", line 538, in thread_handler
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
    return view_func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/opt/venv/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/opt/venv/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  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/engine/views.py", line 1297, in annotations
    self._object = self.get_object() # force call of check_object_permissions()
  File "/opt/venv/lib/python3.10/site-packages/rest_framework/generics.py", line 99, in get_object
    self.check_object_permissions(self.request, obj)
  File "/opt/venv/lib/python3.10/site-packages/rest_framework/views.py", line 345, in check_object_permissions
    if not permission.has_object_permission(request, self, obj):
  File "/home/django/cvat/apps/iam/permissions.py", line 2023, in has_object_permission
    return self.check_permission(request, view, obj)
  File "/home/django/cvat/apps/iam/permissions.py", line 2007, in check_permission
    permissions.extend(perm.create(request, view, obj, iam_context))
  File "/home/django/cvat/apps/iam/permissions.py", line 915, in create
    permissions.append(CloudStoragePermission.create_scope_view(
  File "/home/django/cvat/apps/iam/permissions.py", line 630, in create_scope_view
    obj = CloudStorage.objects.get(id=storage_id)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 623, in get
    clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1436, in filter
    return self._filter_or_exclude(False, args, kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1454, in _filter_or_exclude
    clone._filter_or_exclude_inplace(negate, args, kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1461, in _filter_or_exclude_inplace
    self._query.add_q(Q(*args, **kwargs))
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1534, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1565, in _add_q
    child_clause, needed_inner = self.build_filter(
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1480, in build_filter
    condition = self.build_lookup(lookups, col, value)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1307, in build_lookup
    lookup = lookup_class(lhs, rhs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/lookups.py", line 27, in __init__
    self.rhs = self.get_prep_lookup()
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/lookups.py", line 341, in get_prep_lookup
    return super().get_prep_lookup()
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/lookups.py", line 85, in get_prep_lookup
    return self.lhs.output_field.get_prep_value(self.rhs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 2055, in get_prep_value
    raise e.__class__(
ValueError: Field 'id' expected a number but got '1.0'.

Possible Solution

  1. Update cloud_storage_id validation type to int?
  2. If it must be float, then handle float values in server

Context

I'm trying to write a cron script which will backup annotations every day to cloud storage.

Your Environment

  • CVAT server: 2.6
  • Docker version: 20.10.18
@Marishka17 Marishka17 added the bug Something isn't working label Sep 6, 2023
nmanovic pushed a commit that referenced this issue Sep 11, 2023
mikhail-treskin pushed a commit to retailnext/cvat that referenced this issue Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants