Skip to content

Commit

Permalink
Deprecates BaseDistribution and related objects
Browse files Browse the repository at this point in the history
This deprecates the following objects and adds warnings when they are
used:

* `pulpcore.plugin.models.BaseDistribution`
* `pulpcore.plugin.viewset.BaseDistributionViewSet`
* `pulpcore.plugin.viewset.DistributionFilter`
* `pulpcore.plugin.serializer.BaseDistributionSerializer`
* `pulpcore.plugin.serializer.PublicationDistributionSerializer`
* `pulpcore.plugin.serializer.RepositoryVersionDistributionSerializer`

closes #8385
  • Loading branch information
bmbouter committed Apr 1, 2021
1 parent 47e5cc2 commit e747954
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
21 changes: 21 additions & 0 deletions CHANGES/plugin_api/8385.deprecation
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The following objects were deprecated:
* ``pulpcore.plugin.models.BaseDistribution`` -- Instead use
``pulpcore.plugin.models.Distribution``.
* ``pulpcore.plugin.viewset.BaseDistributionViewSet`` -- Instead use
``pulpcore.plugin.viewset.DistributionViewSet``.
* ``pulpcore.plugin.serializer.BaseDistributionSerializer`` -- Instead use
``pulpcore.plugin.serializer.DistributionSerializer``.
* ``pulpcore.plugin.serializer.PublicationDistributionSerializer`` -- Instead use define the
``publication`` field directly on your detail distribution object. See the docstring for
``pulpcore.plugin.serializer.DistributionSerializer`` for an example.
* ``pulpcore.plugin.serializer.RepositoryVersionDistributionSerializer`` -- Instead use define the
``repository_version`` field directly on your detail distribution object. See the docstring for
``pulpcore.plugin.serializer.DistributionSerializer`` for an example.
* ``pulpcore.plugin.viewset.DistributionFilter`` -- Instead use
``pulpcore.plugin.viewset.NewDistributionFilter``.

.. note::

You will have to define a migration to move your data from
``pulpcore.plugin.models.BaseDistribution`` to ``pulpcore.plugin.models.Distribution``. See the
pulp_file migration 0009 as a reference example.
14 changes: 14 additions & 0 deletions pulpcore/app/models/publication.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from gettext import gettext as _
import warnings

from django.db import IntegrityError, models, transaction

from .base import MasterModel, BaseModel
Expand Down Expand Up @@ -286,6 +289,17 @@ class BaseDistribution(MasterModel):
content_guard = models.ForeignKey(ContentGuard, null=True, on_delete=models.SET_NULL)
remote = models.ForeignKey(Remote, null=True, on_delete=models.SET_NULL)

def __init__(self, *args, **kwargs):
""" Initialize a BaseDistribution and emit DeprecationWarnings"""
warnings.warn(
_(
"BaseDistribution is deprecated and could be removed as early as pulpcore==3.13; "
"use pulpcore.plugin.models.Distribution instead."
),
DeprecationWarning,
)
return super().__init__(*args, **kwargs)

def content_handler(self, path):
"""
Handler to serve extra, non-Artifact content for this Distribution
Expand Down
36 changes: 36 additions & 0 deletions pulpcore/app/serializers/publication.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from gettext import gettext as _
import warnings

from django.db.models import Q
from rest_framework import serializers
Expand Down Expand Up @@ -129,6 +130,17 @@ class Meta:
"name",
)

def __init__(self, *args, **kwargs):
""" Initialize a BaseDistributionSerializer and emit DeprecationWarnings"""
warnings.warn(
_(
"BaseDistributionSerializer is deprecated and could be removed as early as "
"pulpcore==3.13; use pulpcore.plugin.serializers.DistributionSerializer instead."
),
DeprecationWarning,
)
return super().__init__(*args, **kwargs)

def _validate_path_overlap(self, path):
# look for any base paths nested in path
search = path.split("/")[0]
Expand Down Expand Up @@ -166,6 +178,18 @@ class PublicationDistributionSerializer(BaseDistributionSerializer):
allow_null=True,
)

def __init__(self, *args, **kwargs):
""" Initialize a PublicationDistributionSerializer and emit DeprecationWarnings"""
warnings.warn(
_(
"PublicationDistributionSerializer is deprecated and could be removed as early as "
"pulpcore==3.13; use pulpcore.plugin.serializers.DistributionSerializer instead. "
"See its docstring for more details."
),
DeprecationWarning,
)
return super().__init__(*args, **kwargs)

class Meta:
abstract = True
fields = BaseDistributionSerializer.Meta.fields + ("publication",)
Expand All @@ -183,6 +207,18 @@ class RepositoryVersionDistributionSerializer(BaseDistributionSerializer):
required=False, help_text=_("RepositoryVersion to be served"), allow_null=True
)

def __init__(self, *args, **kwargs):
""" Initialize a RepositoryVersionDistributionSerializer and emit DeprecationWarnings"""
warnings.warn(
_(
"PublicationDistributionSerializer is deprecated and could be removed as early as "
"pulpcore==3.13; use pulpcore.plugin.serializers.DistributionSerializer instead. "
"See its docstring for more details."
),
DeprecationWarning,
)
return super().__init__(*args, **kwargs)

class Meta:
abstract = True
fields = BaseDistributionSerializer.Meta.fields + ("repository", "repository_version")
Expand Down
25 changes: 25 additions & 0 deletions pulpcore/app/viewsets/publication.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from gettext import gettext as _
import warnings

from django_filters.rest_framework import DjangoFilterBackend, filters
from rest_framework import mixins
from rest_framework.filters import OrderingFilter
Expand Down Expand Up @@ -98,6 +101,17 @@ class DistributionFilter(BaseFilterSet):
base_path = filters.CharFilter()
pulp_label_select = LabelSelectFilter()

def __init__(self, *args, **kwargs):
""" Initialize a DistributionFilter and emit DeprecationWarnings"""
warnings.warn(
_(
"DistributionFilter is deprecated and could be removed as early as "
"pulpcore==3.13; use pulpcore.plugin.serializers.NewDistributionFilter instead."
),
DeprecationWarning,
)
return super().__init__(*args, **kwargs)

class Meta:
model = BaseDistribution
fields = {
Expand Down Expand Up @@ -125,6 +139,17 @@ class BaseDistributionViewSet(
serializer_class = BaseDistributionSerializer
filterset_class = DistributionFilter

def __init__(self, *args, **kwargs):
""" Initialize a BaseDistributionViewSet and emit DeprecationWarnings"""
warnings.warn(
_(
"BaseDistributionViewSet is deprecated and could be removed as early as "
"pulpcore==3.13; use pulpcore.plugin.viewsets.DistributionViewset instead."
),
DeprecationWarning,
)
return super().__init__(*args, **kwargs)

def async_reserved_resources(self, instance):
"""Return resource that locks all Distributions."""
return ["/api/v3/distributions/"]

0 comments on commit e747954

Please sign in to comment.