Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ minio_access_key: "'$MINIO_ACCESS_KEY'"\
minio_secret_key: "'$MINIO_SECRET_KEY'"\
pulp_scenario_settings: null\
pulp_scenario_env: {}\
test_storages_compat_layer: false\
test_storages_compat_layer: true\
' vars/main.yaml
export PULP_API_ROOT="/rerouted/djnd/"
fi
Expand Down
2 changes: 1 addition & 1 deletion functest_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
django # TODO: test_sync.py has a dependency on date parsing functions
git+https://github.com/pulp/pulp-smash.git#egg=pulp-smash
productmd>=1.25
pytest<8
dictdiffer
Expand All @@ -10,3 +9,4 @@ pyzstd
requests
pytest-xdist
pytest-timeout
pytest-custom_exit_code
7 changes: 0 additions & 7 deletions pulp_rpm/app/fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from rest_framework import serializers
from drf_spectacular.utils import extend_schema_field
from drf_spectacular.types import OpenApiTypes
from pulp_rpm.app.constants import ADVISORY_SUM_TYPE_TO_NAME
from pulp_rpm.app.models import UpdateReference

Expand Down Expand Up @@ -75,8 +73,3 @@ def to_representation(self, value):
}
)
return ret


@extend_schema_field(OpenApiTypes.OBJECT)
class CustomJSONField(serializers.JSONField):
"""A (drf) JSONField override to force openapi schema to use 'object' type."""
3 changes: 1 addition & 2 deletions pulp_rpm/app/serializers/advisory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import createrepo_c
from django.db import IntegrityError, transaction
from rest_framework import serializers
from pulp_rpm.app.fields import CustomJSONField

from pulpcore.plugin.serializers import (
ModelSerializer,
Expand Down Expand Up @@ -44,7 +43,7 @@ class UpdateCollectionSerializer(ModelSerializer):
help_text=_("Collection short name."), allow_blank=True, allow_null=True
)

module = CustomJSONField(help_text=_("Collection modular NSVCA."), allow_null=True)
module = serializers.JSONField(help_text=_("Collection modular NSVCA."), allow_null=True)

packages = UpdateCollectionPackagesField(
source="*", read_only=True, help_text=_("List of packages")
Expand Down
27 changes: 15 additions & 12 deletions pulp_rpm/app/serializers/comps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from gettext import gettext as _

from rest_framework import serializers
from pulp_rpm.app.fields import CustomJSONField

from pulpcore.plugin.models import Repository
from pulpcore.plugin.serializers import DetailRelatedField
Expand Down Expand Up @@ -32,12 +31,14 @@ class PackageGroupSerializer(NoArtifactContentSerializer):
)
name = serializers.CharField(help_text=_("PackageGroup name."), allow_blank=True)
description = serializers.CharField(help_text=_("PackageGroup description."), allow_blank=True)
packages = CustomJSONField(help_text=_("PackageGroup package list."), allow_null=True)
packages = serializers.JSONField(help_text=_("PackageGroup package list."), allow_null=True)
biarch_only = serializers.BooleanField(help_text=_("PackageGroup biarch only."), required=False)
desc_by_lang = CustomJSONField(
desc_by_lang = serializers.JSONField(
help_text=_("PackageGroup description by language."), allow_null=True
)
name_by_lang = CustomJSONField(help_text=_("PackageGroup name by language."), allow_null=True)
name_by_lang = serializers.JSONField(
help_text=_("PackageGroup name by language."), allow_null=True
)
digest = serializers.CharField(
help_text=_("PackageGroup digest."),
)
Expand Down Expand Up @@ -72,11 +73,11 @@ class PackageCategorySerializer(NoArtifactContentSerializer):
display_order = serializers.IntegerField(
help_text=_("Category display order."), allow_null=True
)
group_ids = CustomJSONField(help_text=_("Category group list."), allow_null=True)
desc_by_lang = CustomJSONField(
group_ids = serializers.JSONField(help_text=_("Category group list."), allow_null=True)
desc_by_lang = serializers.JSONField(
help_text=_("Category description by language."), allow_null=True
)
name_by_lang = CustomJSONField(help_text=_("Category name by language."), allow_null=True)
name_by_lang = serializers.JSONField(help_text=_("Category name by language."), allow_null=True)
digest = serializers.CharField(
help_text=_("Category digest."),
)
Expand Down Expand Up @@ -108,12 +109,14 @@ class PackageEnvironmentSerializer(NoArtifactContentSerializer):
display_order = serializers.IntegerField(
help_text=_("Environment display order."), allow_null=True
)
group_ids = CustomJSONField(help_text=_("Environment group list."), allow_null=True)
option_ids = CustomJSONField(help_text=_("Environment option ids"), allow_null=True)
desc_by_lang = CustomJSONField(
group_ids = serializers.JSONField(help_text=_("Environment group list."), allow_null=True)
option_ids = serializers.JSONField(help_text=_("Environment option ids"), allow_null=True)
desc_by_lang = serializers.JSONField(
help_text=_("Environment description by language."), allow_null=True
)
name_by_lang = CustomJSONField(help_text=_("Environment name by language."), allow_null=True)
name_by_lang = serializers.JSONField(
help_text=_("Environment name by language."), allow_null=True
)
digest = serializers.CharField(help_text=_("Environment digest."))

class Meta:
Expand All @@ -136,7 +139,7 @@ class PackageLangpacksSerializer(NoArtifactContentSerializer):
PackageLangpacks serializer.
"""

matches = CustomJSONField(help_text=_("Langpacks matches."), allow_null=True)
matches = serializers.JSONField(help_text=_("Langpacks matches."), allow_null=True)
digest = serializers.CharField(help_text=_("Langpacks digest."), allow_null=True)

class Meta:
Expand Down
9 changes: 4 additions & 5 deletions pulp_rpm/app/serializers/modulemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from pulpcore.plugin.serializers import DetailRelatedField, NoArtifactContentSerializer
from rest_framework import serializers
from pulp_rpm.app.fields import CustomJSONField

from pulp_rpm.app.models import Modulemd, ModulemdDefaults, ModulemdObsolete, Package

Expand Down Expand Up @@ -32,8 +31,8 @@ class ModulemdSerializer(NoArtifactContentSerializer):
arch = serializers.CharField(
help_text=_("Modulemd architecture."),
)
artifacts = CustomJSONField(help_text=_("Modulemd artifacts."), allow_null=True)
dependencies = CustomJSONField(help_text=_("Modulemd dependencies."), allow_null=True)
artifacts = serializers.JSONField(help_text=_("Modulemd artifacts."), allow_null=True)
dependencies = serializers.JSONField(help_text=_("Modulemd dependencies."), allow_null=True)
# TODO: The performance of this is not great, there's a noticable difference in response
# time before/after. Since this will only return Package content hrefs, we might benefit
# from creating a specialized version of this Field that can skip some of the work.
Expand All @@ -46,7 +45,7 @@ class ModulemdSerializer(NoArtifactContentSerializer):
view_name="content-rpm/packages-detail",
many=True,
)
profiles = CustomJSONField(help_text=_("Modulemd profiles."), allow_null=True)
profiles = serializers.JSONField(help_text=_("Modulemd profiles."), allow_null=True)
snippet = serializers.CharField(help_text=_("Modulemd snippet"), write_only=True)

def create(self, validated_data):
Expand Down Expand Up @@ -88,7 +87,7 @@ class ModulemdDefaultsSerializer(NoArtifactContentSerializer):

module = serializers.CharField(help_text=_("Modulemd name."))
stream = serializers.CharField(help_text=_("Modulemd default stream."))
profiles = CustomJSONField(help_text=_("Default profiles for modulemd streams."))
profiles = serializers.JSONField(help_text=_("Default profiles for modulemd streams."))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the distinction between serializers.JSONField, JSONDictField, and JSONListField ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. serializers.JSONField (drf) accept any json type (bool, str, object, array, ...) and has openapi type any.
  2. JSONDictField (custom) validates it's a json object (aka dict) and has openapi type object.
  3. JSONListField (custom) validates it's a json array (aka list) and has openapi type array.

2 and 3 subclasses from 1 and then adds the layer of validation.

But actually I found that my implementation of 2 and 3 is wrong.
I should either:

a) add the correct version of these fields here to get the types and validation right
b) use the serializers.JSONField which will change the types we use in openapi to any (which will probably not break ruby bindings this time because the new bindindg generator image probably supports any type)

Copy link
Contributor

@dralley dralley Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

B) is what the python plugin just did I believe

pulp/pulp_python#791

Copy link
Member Author

@pedro-psb pedro-psb Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I'll do that here as there is already a lot going on

snippet = serializers.CharField(help_text=_("Modulemd default snippet"), write_only=True)

def create(self, validated_data):
Expand Down
21 changes: 10 additions & 11 deletions pulp_rpm/app/serializers/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
)
from pulpcore.plugin.util import get_domain_pk
from rest_framework import serializers
from pulp_rpm.app.fields import CustomJSONField
from rest_framework.exceptions import NotAcceptable

from pulp_rpm.app.models import Package
Expand Down Expand Up @@ -78,62 +77,62 @@ class PackageSerializer(SingleArtifactContentUploadSerializer, ContentChecksumSe
read_only=True,
)

changelogs = CustomJSONField(
changelogs = serializers.JSONField(
help_text=_("Changelogs that package contains"),
default="[]",
required=False,
read_only=True,
)
files = CustomJSONField(
files = serializers.JSONField(
help_text=_("Files that package contains"),
default="[]",
required=False,
read_only=True,
)

requires = CustomJSONField(
requires = serializers.JSONField(
help_text=_("Capabilities the package requires"),
default="[]",
required=False,
read_only=True,
)
provides = CustomJSONField(
provides = serializers.JSONField(
help_text=_("Capabilities the package provides"),
default="[]",
required=False,
read_only=True,
)
conflicts = CustomJSONField(
conflicts = serializers.JSONField(
help_text=_("Capabilities the package conflicts"),
default="[]",
required=False,
read_only=True,
)
obsoletes = CustomJSONField(
obsoletes = serializers.JSONField(
help_text=_("Capabilities the package obsoletes"),
default="[]",
required=False,
read_only=True,
)
suggests = CustomJSONField(
suggests = serializers.JSONField(
help_text=_("Capabilities the package suggests"),
default="[]",
required=False,
read_only=True,
)
enhances = CustomJSONField(
enhances = serializers.JSONField(
help_text=_("Capabilities the package enhances"),
default="[]",
required=False,
read_only=True,
)
recommends = CustomJSONField(
recommends = serializers.JSONField(
help_text=_("Capabilities the package recommends"),
default="[]",
required=False,
read_only=True,
)
supplements = CustomJSONField(
supplements = serializers.JSONField(
help_text=_("Capabilities the package supplements"),
default="[]",
required=False,
Expand Down
22 changes: 18 additions & 4 deletions pulp_rpm/app/serializers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
)
from pulpcore.plugin.util import get_domain, resolve_prn
from rest_framework import serializers
from pulp_rpm.app.fields import CustomJSONField

from pulp_rpm.app.constants import (
ALLOWED_CHECKSUM_ERROR_MSG,
Expand Down Expand Up @@ -147,11 +146,26 @@ class RpmRepositorySerializer(RepositorySerializer):
),
read_only=True,
)
repo_config = CustomJSONField(
repo_config = serializers.JSONField(
required=False,
help_text=_("A JSON document describing config.repo file"),
)

def to_representation(self, instance):
data = super().to_representation(instance)
# Import workflow may cause these fields to be stored as "" in the database
Copy link
Contributor

@dralley dralley Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a separate codepath that ought to be adjusted here? Anything to fix with a data migration? Ideally we want total consistency w/ how values are stored in a field.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that we can fix import-export workflow to ensure it stores null values and add migration to fix empty strings. I can open an issue for that.

# This ensure the correct type of None | Enum in the response
for field in (
"checksum_type",
"metadata_checksum_type",
"package_checksum_type",
"compression_type",
):
field_data = data.get(field)
if field_data == "":
data[field] = None
return data

def validate(self, data):
"""Validate data."""
for field in ("checksum_type", "metadata_checksum_type", "package_checksum_type"):
Expand Down Expand Up @@ -410,7 +424,7 @@ class RpmPublicationSerializer(PublicationSerializer):
),
read_only=True,
)
repo_config = CustomJSONField(
repo_config = serializers.JSONField(
required=False,
help_text=_("A JSON document describing config.repo file"),
)
Expand Down Expand Up @@ -549,7 +563,7 @@ class CopySerializer(ValidateFieldsMixin, serializers.Serializer):
A serializer for Content Copy API.
"""

config = CustomJSONField(
config = serializers.JSONField(
help_text=_(
dedent(
"""\
Expand Down
Loading