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
1 change: 1 addition & 0 deletions CHANGES/7677.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow nested downloader_config to be passed json stringified.
6 changes: 5 additions & 1 deletion pulp_file/tests/functional/api/test_crud_content_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ def test_create_file_from_url(
):
# Test create w/ url
remote = file_remote_factory(manifest_path=basic_manifest_path)
body = {"file_url": remote.url, "relative_path": "PULP_MANIFEST"}
body = {
"file_url": remote.url,
"relative_path": "PULP_MANIFEST",
"downloader_config": {"total_timeout": 5},
}
response = file_bindings.ContentFilesApi.create(**body)
task = monitor_task(response.task)
assert len(task.created_resources) == 1
Expand Down
21 changes: 19 additions & 2 deletions pulpcore/app/serializers/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import functools
import json
import re
import traceback
from collections import namedtuple
Expand Down Expand Up @@ -80,7 +81,7 @@ def to_internal_value(self, data):
return super().to_internal_value(data)


class _MatchingRegexViewName(object):
class _MatchingRegexViewName:
"""This is a helper class to help defining object matching rules for master-detail.

If you can be specific, please specify the `view_name`, but if you cannot, this allows
Expand Down Expand Up @@ -306,7 +307,11 @@ def validate_unknown_fields(initial_data, defined_fields):
The `csrfmiddlewaretoken` field is silently ignored.
"""
ignored_fields = {"csrfmiddlewaretoken"}
unknown_fields = set(initial_data) - set(defined_fields) - ignored_fields
unknown_fields = (
{key.split(".", maxsplit=1)[0] for key in initial_data}
- set(defined_fields)
- ignored_fields
)
if unknown_fields:
unknown_fields = {field: _("Unexpected field") for field in unknown_fields}
raise serializers.ValidationError(unknown_fields)
Expand Down Expand Up @@ -778,11 +783,23 @@ def _validate_certificate(which_cert, value):
"Invalid {} specified, error '{}'".format(which_cert, e.args)
)

def to_internal_value(self, data):
if isinstance(data, str):
try:
# Nested Serializers in from-urlencoded bodies are stringified as json by default.
data = json.loads(data)
except json.DecodeError:
raise serializers.ValidationError(
"Invalid json data for (nested) downloader config."
)
return super().to_internal_value(data)

def validate(self, data):
"""
Check that proxy credentials are only provided completely and if a proxy is configured.
Adapted to work for both ModelSerializers (Remotes) and standard Serializers (Uploads).
"""
data = super().validate(data)
# Handle cases where we don't have an instance (e.g. Uploads)
instance = getattr(self, "instance", None)
partial = getattr(self, "partial", False)
Expand Down
Loading