Can't reverse non-API URLs with NamespaceVersioning · Issue #2711 · encode/django-rest-framework (original) (raw)
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?