Skip to content

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

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

Closed
delinhabit opened this issue Mar 18, 2015 · 2 comments · Fixed by #2724
Closed

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

delinhabit opened this issue Mar 18, 2015 · 2 comments · Fixed by #2724

Comments

@delinhabit
Copy link
Contributor

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?

@tomchristie
Copy link
Member

One idea would be to automatically fallback to default reversal if the namespaced one fails.

That sounds okay, yes. Maybe consider having a look at making that change in the NamespacedVersioning scheme and issuing a pull request with that plus a test.

@delinhabit
Copy link
Contributor Author

Sure, I'll do that!

@tomchristie tomchristie added this to the 3.1.1 Release milestone Mar 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants