|
13 | 13 | from rest_framework.decorators import action |
14 | 14 | from rest_framework.generics import get_object_or_404 |
15 | 15 | from rest_framework.response import Response |
16 | | -from pulpcore.openapi import PulpAutoSchema |
| 16 | +from pulpcore.openapi import PulpAutoSchema, InheritSerializer |
17 | 17 | from rest_framework.serializers import ValidationError as DRFValidationError, ListField, CharField |
18 | 18 |
|
19 | 19 | from pulpcore.app import tasks |
@@ -482,27 +482,31 @@ class AsyncUpdateMixin(AsyncReservedObjectMixin): |
482 | 482 | ALLOW_NON_BLOCKING_UPDATE = True |
483 | 483 |
|
484 | 484 | @extend_schema( |
485 | | - description="Trigger an asynchronous update task", |
486 | | - responses={202: AsyncOperationResponseSerializer}, |
| 485 | + description="Update the entity and trigger an asynchronous task if necessary", |
| 486 | + responses={200: InheritSerializer, 202: AsyncOperationResponseSerializer}, |
487 | 487 | ) |
488 | 488 | def update(self, request, pk, **kwargs): |
489 | 489 | partial = kwargs.pop("partial", False) |
490 | 490 | instance = self.get_object() |
491 | 491 | serializer = self.get_serializer(instance, data=request.data, partial=partial) |
492 | 492 | serializer.is_valid(raise_exception=True) |
493 | | - app_label = instance._meta.app_label |
494 | | - task = dispatch( |
495 | | - tasks.base.ageneral_update, |
496 | | - exclusive_resources=self.async_reserved_resources(instance), |
497 | | - args=(pk, app_label, serializer.__class__.__name__), |
498 | | - kwargs={"data": request.data, "partial": partial}, |
499 | | - immediate=self.ALLOW_NON_BLOCKING_UPDATE, |
500 | | - ) |
501 | | - return OperationPostponedResponse(task, request) |
| 493 | + |
| 494 | + if all(getattr(instance, key) == value for key, value in serializer.validated_data.items()): |
| 495 | + return Response(serializer.data) |
| 496 | + else: |
| 497 | + app_label = instance._meta.app_label |
| 498 | + task = dispatch( |
| 499 | + tasks.base.ageneral_update, |
| 500 | + exclusive_resources=self.async_reserved_resources(instance), |
| 501 | + args=(pk, app_label, serializer.__class__.__name__), |
| 502 | + kwargs={"data": request.data, "partial": partial}, |
| 503 | + immediate=self.ALLOW_NON_BLOCKING_UPDATE, |
| 504 | + ) |
| 505 | + return OperationPostponedResponse(task, request) |
502 | 506 |
|
503 | 507 | @extend_schema( |
504 | | - description="Trigger an asynchronous partial update task", |
505 | | - responses={202: AsyncOperationResponseSerializer}, |
| 508 | + description="Update the entity partially and trigger an asynchronous task if necessary", |
| 509 | + responses={200: InheritSerializer, 202: AsyncOperationResponseSerializer}, |
506 | 510 | ) |
507 | 511 | def partial_update(self, request, *args, **kwargs): |
508 | 512 | kwargs["partial"] = True |
|
0 commit comments