Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix openapi schema for created resources #6111

Merged
merged 3 commits into from
Dec 9, 2024
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/+created_resource_schema.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed the schema definition for created resources.
1 change: 1 addition & 0 deletions CHANGES/+task_error_schema.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed the openapi schema definition of task error.
6 changes: 3 additions & 3 deletions pulpcore/app/serializers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def to_representation(self, data):
if repo_ver_mapping is not None:
if repo_ver := repo_ver_mapping.get(data.object_id):
return self.repo_ver_url(repo_ver, request=request)
return None
return "<unavailable>"
else:
try:
view_name = get_view_name_for_model(model, "detail")
Expand All @@ -229,10 +229,10 @@ def to_representation(self, data):
# Fallback onto normal lookup:
# If the content object was deleted
if data.content_object is None:
return None
return "<unavailable>"
try:
if not data.content_object.complete:
return None
return "<unavailable>"
except AttributeError:
pass

Expand Down
7 changes: 3 additions & 4 deletions pulpcore/app/serializers/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from pulpcore.app.util import reverse


class CreatedResourceSerializer(RelatedResourceField):
class CreatedResourceField(RelatedResourceField):
class Meta:
model = models.CreatedResource
fields = []
Expand Down Expand Up @@ -46,8 +46,7 @@ class TaskSerializer(ModelSerializer):
finished_at = serializers.DateTimeField(
help_text=_("Timestamp of when this task stopped execution."), read_only=True
)
error = serializers.DictField(
child=fields.JSONDictField(),
Copy link
Member

Choose a reason for hiding this comment

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

There is a difference in the structure declaration here:

# DictField with child=JSONDictFeild
{
    "key1": { ... },
    ...
    "keyk": { ... }
}

# JSONDictField
{
    "key1": Any,
    ...
    "keyk": Any
}

I think I would keep the DictField. The JSONDictField is meant to replace mainly the generic JSONFields where applicable. I dont see a strong reason for doing so here. Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

The thing is that the errors as reported by pulp seem to be dicts of any. I'll try and dig up examples.

Copy link
Member Author

Choose a reason for hiding this comment

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

Here you are: It's a dict of mainly strings.

[task.error for task in Task.objects.filter(state="failed")]
[{'traceback': '  File "/usr/local/lib/python3.9/site-packages/pulpcore/tasking/tasks.py", line 68, in _execute_task\n
[...]

Copy link
Member

Choose a reason for hiding this comment

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

That looks reasonable then

error = fields.JSONDictField(
help_text=_(
"A JSON Object of a fatal error encountered during the execution of this task."
),
Expand Down Expand Up @@ -78,7 +77,7 @@ class TaskSerializer(ModelSerializer):
view_name="task-groups-detail",
)
progress_reports = ProgressReportSerializer(many=True, read_only=True)
created_resources = CreatedResourceSerializer(
created_resources = CreatedResourceField(
help_text=_("Resources created by this task."),
many=True,
read_only=True,
Expand Down
Loading