Skip to content

Can't reverse non-API URLs with NamespaceVersioning #2711

Closed
@delinhabit

Description

@delinhabit

Hello,

I'm trying to setup a versioning mechanism using NamespaceVersioning as the method. Everything is fine except for the serializer fields that are using non-API views. The reverse function shipped with DRF will raise an exception because it's trying to reverse the non-API views from the same namespace as in request.version.

Here's an example:

class ConversationSerializer(serializers.Serializer):
    url = serializers.HyperlinkedIdentityField(
        view_name='conversation-detail',  # This is an API view under v2 or v3 namespace
        lookup_url_kwargs='conversation_id')
    web_url = serializers.HyperlinkedIdentityField(
        view_name='account-conversation-detail',  # This is a non-API view, without a namespace
        lookup_url_kwargs='conversation_id')

I feel we should do something about this in DRF itself, but I'm not sure how to tackle the issue (at least to document this behavior). One idea would be to automatically fallback to default reversal if the namespaced one fails.

Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions