Skip to content

Commit 063fa04

Browse files
committed
Remove special lock handling for distributions
The base_path integrity is maintained by a database constraint now.
1 parent 6fc7de4 commit 063fa04

2 files changed

Lines changed: 6 additions & 41 deletions

File tree

pulpcore/app/viewsets/base.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -429,27 +429,20 @@ def async_reserved_resources(self, instance, **kwargs):
429429
430430
This default implementation locks the instance being worked on.
431431
432-
.. note::
433-
434-
This does not work for [pulpcore.app.viewsets.AsyncCreateMixin][]
435-
(as there is no instance). Classes using [pulpcore.app.viewsets.AsyncCreateMixin][]
436-
must override this method.
437-
438432
Args:
439-
instance (django.models.Model): The instance that will be worked
433+
instance (django.models.Model | None): The instance that will be worked
440434
on by the task.
441435
442436
Returns:
443-
list/str: The resources to put in the task's reservation
437+
list[django.models.Model | str]: The resources to put in the task's reservation
444438
445439
Raises:
446440
AssertionError if instance is None (which happens for creation)
447441
448442
"""
449-
assert instance is not None, (
450-
"'{}' must not use the default `async_reserved_resources` method when using create."
451-
).format(self.__class__.__name__)
452-
return [instance]
443+
if instance is not None:
444+
return [instance]
445+
return []
453446

454447
def async_shared_resources(self, instance, **kwargs):
455448
"""
@@ -460,7 +453,7 @@ def async_shared_resources(self, instance, **kwargs):
460453
return []
461454

462455

463-
class AsyncCreateMixin:
456+
class AsyncCreateMixin(AsyncReservedObjectMixin):
464457
"""
465458
Provides a create method that dispatches a task with reservation.
466459
"""

pulpcore/app/viewsets/publication.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -526,34 +526,6 @@ def get_queryset(self):
526526
)
527527
return qs
528528

529-
def async_reserved_resources(self, instance):
530-
"""
531-
Reserve safe distribution locks for async operations.
532-
533-
The explicit distribution.base_path lock protects the domain-wide base_path invariant.
534-
The older domain-scoped distributions lock remains shared so tasks queued before an upgrade
535-
still overlap safely with new tasks.
536-
"""
537-
distribution_base_path = f"pdrn:{get_domain().pulp_id}:distribution.base_path"
538-
if instance is None:
539-
return [distribution_base_path]
540-
541-
if getattr(self, "action", "") == "destroy":
542-
return [instance]
543-
544-
request_data = getattr(getattr(self, "request", None), "data", {})
545-
requested_base_path = request_data.get("base_path", instance.base_path)
546-
if requested_base_path == instance.base_path:
547-
return [instance]
548-
549-
return [instance, distribution_base_path]
550-
551-
def async_shared_resources(self, instance):
552-
"""
553-
Keep the legacy domain-scoped distribution lock shared for upgrade compatibility.
554-
"""
555-
return [f"pdrn:{get_domain().pulp_id}:distributions"]
556-
557529

558530
class ListDistributionViewSet(BaseDistributionViewSet, mixins.ListModelMixin):
559531
DEFAULT_ACCESS_POLICY = {

0 commit comments

Comments
 (0)