Skip to content

Commit

Permalink
Invalidate queryset caches of Task and Job model on User delete
Browse files Browse the repository at this point in the history
Task and Job models have many to one relationship with User model on assignee and reviewer fields. And on deleting the parent model, these fields are set to NULL.
However due to an open issue in django-cacheops package, the related querysets are not invalidated upon deletion of parent model. Refer - Suor/django-cacheops#348.
So we have to manually invalidate the cached querysets.
  • Loading branch information
g-kartik committed Jan 2, 2022
1 parent 7bdac66 commit 28a0f81
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cvat/apps/engine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import cv2
from django.db.models.query import Prefetch
import django_rq
from cacheops import invalidate_model
from django.apps import apps
from django.conf import settings
from django.contrib.auth.models import User
Expand Down Expand Up @@ -1092,6 +1093,12 @@ def self(self, request):
serializer = serializer_class(request.user, context={ "request": request })
return Response(serializer.data)

def perform_destroy(self, instance):
super(UserViewSet, self).perform_destroy(instance)
invalidate_model(Task)
invalidate_model(Job)


class RedefineDescriptionField(FieldInspector):
# pylint: disable=no-self-use
def process_result(self, result, method_name, obj, **kwargs):
Expand Down

0 comments on commit 28a0f81

Please sign in to comment.