feat: base 优化get_object事务

This commit is contained in:
caoqianming 2025-09-12 14:47:50 +08:00
parent 57a61daa66
commit 5ece330457
1 changed files with 5 additions and 2 deletions

View File

@ -20,6 +20,7 @@ from drf_yasg.utils import swagger_auto_schema
import json
from django.db import connection
from django.core.exceptions import ObjectDoesNotExist
from django.db.utils import NotSupportedError
class CustomGenericViewSet(MyLoggingMixin, GenericViewSet):
"""
@ -109,9 +110,11 @@ class CustomGenericViewSet(MyLoggingMixin, GenericViewSet):
filter_kwargs = {self.lookup_field: self.kwargs[lookup_url_kwarg]}
try:
obj = queryset.select_for_update().get(**filter_kwargs)
obj = queryset.get(**filter_kwargs)
l_obj = queryset.model.objects.select_for_update().get(pk=obj.pk)
self.check_object_permissions(self.request, obj)
return obj
return l_obj
except ObjectDoesNotExist:
raise Http404
else: