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
Define schema for detail routes. #60
Conversation
pulp_file/app/viewsets.py
Outdated
| raise serializers.ValidationError(detail=_('Repository URI must be specified.')) | ||
| repository = self.get_resource(repository_uri, Repository) | ||
| serializer = _RepositorySyncURLSerializer(data=request.data) | ||
| if not serializer.is_valid(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably just call serializer.is_valid(raise_exception=True) here
pulp_file/app/viewsets.py
Outdated
| @@ -28,6 +28,37 @@ class Meta: | |||
| ] | |||
|
|
|||
|
|
|||
| class _URLField(serializers.URLField): | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why subclass URLField instead of using default URLField?
pulp_file/app/viewsets.py
Outdated
| def publish(self, request, pk): | ||
| serializer = _RepositoryPublishURLSerializer(data=request.data) | ||
| if not serializer.is_valid(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably just call serializer.is_valid(raise_exception=True) here
pulp_file/app/viewsets.py
Outdated
| publisher = self.get_object() | ||
| repository = None | ||
| repository_version = None | ||
| if 'repository' not in request.data and 'repository_version' not in request.data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend cleaning up this logic a bit:
--- a/pulp_file/app/viewsets.py
+++ b/pulp_file/app/viewsets.py
@@ -121,23 +121,20 @@ class FilePublisherViewSet(PublisherViewSet):
repository_uri = serializer.data.get('repository')
repository_version_uri = serializer.data.get('repository_version')
publisher = self.get_object()
- repository, repository_version = None, None
+
if not repository_uri and not repository_version_uri:
raise serializers.ValidationError(_("Either the 'repository' or 'repository_version' "
"need to be specified."))
- if repository_uri:
- repository = self.get_resource(repository_uri, Repository)
-
- if repository_version_uri:
- repository_version = self.get_resource(repository_version_uri, RepositoryVersion)
-
- if repository and repository_version:
+ elif repository_uri and repository_version_uri:
raise serializers.ValidationError(_("Either the 'repository' or 'repository_version' "
"can be specified - not both."))
-
- if not repository_version:
+ elif repository_uri:
+ repository = self.get_resource(repository_uri, Repository)
repository_version = RepositoryVersion.latest(repository)
+ else:
+ repository_version = self.get_resource(repository_version_uri, RepositoryVersion)
+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done @dparalen! I thought for sure we needed to make upstream changes to drf_openapi to get this to work but I'm so glad you found a suitable solution 🥇 🥂
I'm running into some issues publishing a repository_version http POST $PUBLISHER_HREF'publish/' repository_version=http://pulp3.dev:8000/api/v3/repositories/30ed44e8-f0c3-434c-8bea-d4f646d90f61/versions/1/
Is this the right POST request?
File "/home/vagrant/devel/pulp_file/pulp_file/app/viewsets.py", line 136, in publish
repository_version = self.get_resource(repository_version_uri, RepositoryVersion)
File "/home/vagrant/devel/pulp/pulpcore/pulpcore/app/viewsets/base.py", line 64, in get_resource
pk = match.kwargs['pk']
efdd634
to
bbe3296
Compare
|
Hello @dparalen! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on March 23, 2018 at 21:02 Hours UTC |
bbe3296
to
cf8baa2
Compare
|
@werwty thanks for the review and the kind words! :D Unfortunately, I wasn't able to reproduce your error but maybe I'm running out-of-date core... Cheers, |
| required=False | ||
| ) | ||
|
|
||
| def validate(self, data): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
pulp_file/app/viewsets.py
Outdated
| @@ -82,27 +114,18 @@ class FilePublisherViewSet(PublisherViewSet): | |||
| queryset = FilePublisher.objects.all() | |||
| serializer_class = FilePublisherSerializer | |||
|
|
|||
| @detail_route(methods=('post',)) | |||
| @detail_route(methods=('post',), serializer_class=_RepositoryPublishURLSerializer) | |||
| def publish(self, request, pk): | |||
| publisher = self.get_object() | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@dparalen I'm still running into an error when publishing repository_versions (but not repository). My pulp repo is up to date, and pulp_file is checked out from this PR. Can you check to see if you can reproduce it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that I'm running into this issue: https://pulp.plan.io/issues/3466
Since that's the case, I think this PR is ready for merge, I just left an optional suggestion.
Thanks @dparalen
|
@werwty I just wanted to let you know that indeed that's the issue you're running into and I've been running my core with the fix applied all the time 🙀 |
closes #3351
cf8baa2
to
b33c6d2
Compare
|
@werwty in case my update is OK, please merge this change as I don't have the commit bit ;) Thanks, |
|
@dparalen ha! I also don't have the commit bit. @daviddavis Can you take care of this? |
|
👍 |
|
lol, thanks guys! 😘 |

closes #3351