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

Internal Server Error. When trying to delete a task that was assigned to a deactivated and than removed user. #4088

Closed
2 tasks done
dvkruchinin opened this issue Dec 27, 2021 · 5 comments · Fixed by #4165
Closed
2 tasks done
Assignees
Labels
bug Something isn't working

Comments

@dvkruchinin
Copy link
Contributor

My actions before raising this issue

Internal Server Error. When trying to delete a task that was assigned to a user that was deactivated and then deleted.
A similar situation occurs when trying to delete a task that was created by a user who was deactivated and then deleted.
An error when opening a job that was assigned to a user who was deactivated and then deleted.

Expected Behaviour

It is possible that the task should be deleted.

Current Behaviour

ERROR django.request: Internal Server Error: /api/v1/tasks/182
Traceback (most recent call last):
  File "/opt/venv/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py", line 173, in __get__
    rel_obj = self.field.get_cached_value(instance)
  File "/opt/venv/lib/python3.8/site-packages/django/db/models/fields/mixins.py", line 15, in get_cached_value
    return instance._state.fields_cache[cache_name]
KeyError: 'owner'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/opt/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner    
    response = get_response(request)
  File "/opt/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
  response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/venv/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/opt/venv/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception  
    self.raise_uncaught_exception(exc)
  File "/opt/venv/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/opt/venv/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper        
    return bound_method(*args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/rest_framework/mixins.py", line 90, in destroy
    instance = self.get_object()

2021-12-27 12:49:42,347 DEBG 'runserver' stderr output:
  File "/opt/venv/lib/python3.8/site-packages/rest_framework/generics.py", line 99, in get_object      
    self.check_object_permissions(self.request, obj)
  File "/opt/venv/lib/python3.8/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 968, in has_object_permission
    return self.check_permission(request, view, obj)
  File "/home/django/cvat/apps/iam/permissions.py", line 957, in check_permission
    permissions.extend(perm.create(request, view, obj))
  File "/home/django/cvat/apps/iam/permissions.py", line 511, in create
    self = cls(scope, request, view, obj)
  File "/home/django/cvat/apps/iam/permissions.py", line 554, in __init__
    self.payload['input']['resource'] = self.resource
  File "/home/django/cvat/apps/iam/permissions.py", line 562, in resource
    "owner": { "id": getattr(self.obj.owner, 'id', None) },
  File "/opt/venv/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py", line 187, in __get__
    rel_obj = self.get_object(instance)
  File "/opt/venv/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py", line 154, in get_object
    return qs.get(self.field.get_reverse_related_filter(instance))
  File "/opt/venv/lib/python3.8/site-packages/cacheops/query.py", line 352, in get
    return qs._no_monkey.get(qs, *args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/django/db/models/query.py", line 435, in get
    raise self.model.DoesNotExist(
django.contrib.auth.models.User.DoesNotExist: User matching query does not exist.

log - Internal Server Error: /api/v1/tasks/182
Traceback (most recent call last):
  File "/opt/venv/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py", line 173, in __get__
    rel_obj = self.field.get_cached_value(instance)
  File "/opt/venv/lib/python3.8/site-packages/django/db/models/fields/mixins.py", line 15, in get_cached_value
    return instance._state.fields_cache[cache_name]
KeyError: 'owner'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/opt/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner    
    response = get_response(request)
  File "/opt/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/venv/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/opt/venv/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception  
    self.raise_uncaught_exception(exc)
  File "/opt/venv/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/opt/venv/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper        
    return bound_method(*args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/rest_framework/mixins.py", line 90, in destroy
    instance = self.get_object()
  File "/opt/venv/lib/python3.8/site-packages/rest_framework/generics.py", line 99, in get_object      
   self.check_object_permissions(self.request, obj)
 File "/opt/venv/lib/python3.8/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 968, in has_object_permission
   return self.check_permission(request, view, obj)
 File "/home/django/cvat/apps/iam/permissions.py", line 957, in check_permission
   permissions.extend(perm.create(request, view, obj))
 File "/home/django/cvat/apps/iam/permissions.py", line 511, in create
   self = cls(scope, request, view, obj)
 File "/home/django/cvat/apps/iam/permissions.py", line 554, in __init__
   self.payload['input']['resource'] = self.resource
 File "/home/django/cvat/apps/iam/permissions.py", line 562, in resource
   "owner": { "id": getattr(self.obj.owner, 'id', None) },
 File "/opt/venv/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py", line 187, in __get__
   rel_obj = self.get_object(instance)
 File "/opt/venv/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py", line 154, in get_object
   return qs.get(self.field.get_reverse_related_filter(instance))
 File "/opt/venv/lib/python3.8/site-packages/cacheops/query.py", line 352, in get
   return qs._no_monkey.get(qs, *args, **kwargs)
 File "/opt/venv/lib/python3.8/site-packages/django/db/models/query.py", line 435, in get
raise self.model.DoesNotExist(
django.contrib.auth.models.User.DoesNotExist: User matching query does not exist.

Possible Solution

Fix the bug.

Steps to Reproduce (for bugs)

  1. Create a user and assign a task to him. Deactivate and delete this user. Try to delete the task.
  2. Create a user. Create a task on his behalf. Deactivate and delete the user. Try to delete the task.
  3. Create a user and assign a job to him. Deactivate and delete this user. Try to open the job.

Context

Your Environment

  • Git hash commit (git log -1): 6cabea1
  • Docker version docker version (e.g. Docker 17.0.05): 20.10.7
  • Are you using Docker Swarm or Kubernetes? No
  • Operating System and version (e.g. Linux, Windows, MacOS): Windows 10, Linux
  • Code example or link to GitHub repo or gist to reproduce problem:
  • Other diagnostic information / logs:
    Logs from `cvat` container

Next steps

You may join our Gitter channel for community support.

@bsekachev bsekachev added the bug Something isn't working label Dec 27, 2021
@nmanovic nmanovic self-assigned this Dec 28, 2021
@g-kartik
Copy link
Contributor

g-kartik commented Dec 29, 2021

@nmanovic If you haven't started working on it yet, may I take up this issue?

@nmanovic
Copy link
Contributor

@g-kartik , it will be great! Thanks for your contribution.

@g-kartik
Copy link
Contributor

@g-kartik , it will be great! Thanks for your contribution.

Thank You!

@dvkruchinin
Copy link
Contributor Author

A similar error occurs if the user was in the organization and then was removed from the database (deactivation of the user is not necessary).

@nmanovic
Copy link
Contributor

It looks like it is a problem with using cacheops: Suor/django-cacheops#348

Basically we have code which cache Task.objects.get() and Job.objects.get(): https://github.com/openvinotoolkit/cvat/blob/c9aa9a12e1fd9bacb7bb017c0cf3671616d57e79/cvat/settings/base.py#L326

Solution:

  1. I'm going to cache users instead
  2. I'm not going to cache tasks and jobs for now
  3. I will create an issue about rethinking the caching strategy. Need to understand what to cache and how. It should be in scope of performance optimization task for CVAT server.

nmanovic pushed a commit that referenced this issue Jan 13, 2022
nmanovic pushed a commit that referenced this issue Jan 17, 2022
* Resolved #4088

* Update CHANGELOG

* Fix linter issues

* Removed CACHEOPS settings from production.py
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.

4 participants