pulp_ansible icon indicating copy to clipboard operation
pulp_ansible copied to clipboard

Provide a way for subclasses of pulp viewset that use serializers with href methods to override urls that are reversed

Open pulpbot opened this issue 4 years ago • 1 comments

Author: alikins (alikins)

Redmine Issue: 7032, https://pulp.plan.io/issues/7032


This is related to https://github.com/ansible/galaxy_ng/pull/254 and https://github.com/ansible/galaxy_ng/issues/247

To paraphrase https://github.com/ansible/galaxy_ng/issues/247#issuecomment-644886557:

The serializers used by the pulp collection viewsets (and therefore galaxy_ng collection viewsets) base the values for 'href' on url reverse() lookups, and end up with the pulp paths.

May mean galaxy_ng viewsets need to provide their own serializer.

But may be able to parameterize the reverse()'s to handle both cases. Possibly via providing a ViewSet.get_serializer_context()

https://github.com/ansible/galaxy_ng/pull/254 is a fix / workaround that is based on subclassing the related pulp collection Serializers and overriding the href related SerializerMethodFields methods.

ie, the 'get_href()' and similar methods.

The changes in #254 are kind of cut&paste and duplicate a chunk of pulp_ansible code (and diverge from upstream as a result). So if there is a reasonable way to avoid that it's probably worth while.

https://github.com/ansible/galaxy_ng/issues/247#issuecomment-644983783 mentions a few vague ideas on approaches to handle this issue. In particular, the main #2 point there.

Gist is providing a way for the serializers get_href methods to use a url namespace (or specify url name explicitly) when the viewset classes have been subclassed (as galaxy_ng.app.api.v3.viewsets.collections.CollectionViewSet does).

  • There may be existing django or drf support for doing this but it isn't clear to me yet. (The 'content_app' attribute mentioned in https://github.com/ansible/galaxy_ng/issues/247#issuecomment-644983783 seems like it is intended for exactly this case, but I couldn't get it to work. But that is likely developer error on my part)

  • Maybe this is something drf-nested-routers / rest_framework_nested is meant to support?

pulpbot avatar Nov 17 '21 19:11 pulpbot

From: @bmbouter (bmbouter) Date: 2020-09-22T15:53:55Z


taking of 0.4.0 per check-in meeting w/ @galaxy_ng

pulpbot avatar Nov 17 '21 19:11 pulpbot