Internal Server Error. When trying to delete a task that was assigned to a deactivated and than removed user.
See original GitHub issueMy actions before raising this issue
- Read/searched the docs
- Searched past issues
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)
- Create a user and assign a task to him. Deactivate and delete this user. Try to delete the task.
- Create a user. Create a task on his behalf. Deactivate and delete the user. Try to delete the task.
- 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
): 6cabea1ba5330142b1b6a2c6a00915a61e24fcb2 - 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.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Remove users from SharePoint - SharePoint in Microsoft 365
This issue most frequently occurs when a user is deleted and the account is then re-created with the same user name. The account...
Read more >How to Fix the 500 Internal Server Error in WordPress
If disabling all plugins fixed the error, then you know it is one of the plugins that is causing the error. Simply go...
Read more >delete-service-linked-role — AWS CLI 1.27.34 Command ...
If you submit a deletion request for a service-linked role whose linked service is still accessing a resource, then the deletion task fails....
Read more >Common problems and solutions—Portal for ArcGIS
If my portal uses Active Directory or LDAP accounts and groups, what happens when a user is deleted from my Windows Active Directory...
Read more >Remove a Permission Set License from a User - Salesforce Help
First remove or modify the relevant assigned permission sets that require the license, and then remove the assigned permission set license.Required Editio.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@g-kartik , it will be great! Thanks for your contribution.
It looks like it is a problem with using cacheops: https://github.com/Suor/django-cacheops/issues/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: