diff --git a/awx/api/versioning.py b/awx/api/versioning.py index e9c089e37d..2e00d5cbcb 100644 --- a/awx/api/versioning.py +++ b/awx/api/versioning.py @@ -2,11 +2,31 @@ # All Rights Reserved. from django.conf import settings +from django.core.urlresolvers import NoReverseMatch -from rest_framework.reverse import reverse as drf_reverse +from rest_framework.reverse import _reverse from rest_framework.versioning import URLPathVersioning as BaseVersioning +def drf_reverse(viewname, args=None, kwargs=None, request=None, format=None, **extra): + """ + Copy and monkey-patch `rest_framework.reverse.reverse` to prevent adding unwarranted + query string parameters. + """ + scheme = getattr(request, 'versioning_scheme', None) + if scheme is not None: + try: + url = scheme.reverse(viewname, args, kwargs, request, format, **extra) + except NoReverseMatch: + # In case the versioning scheme reversal fails, fallback to the + # default implementation + url = _reverse(viewname, args, kwargs, request, format, **extra) + else: + url = _reverse(viewname, args, kwargs, request, format, **extra) + + return url + + def get_request_version(request): """ The API version of a request as an integer i.e., 1 or 2 diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 95114c7379..263a0ab569 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -285,7 +285,8 @@ REST_FRAMEWORK = { 'VIEW_NAME_FUNCTION': 'awx.api.generics.get_view_name', 'VIEW_DESCRIPTION_FUNCTION': 'awx.api.generics.get_view_description', 'NON_FIELD_ERRORS_KEY': '__all__', - 'DEFAULT_VERSION': 'v2' + 'DEFAULT_VERSION': 'v2', + #'URL_FORMAT_OVERRIDE': None, } AUTHENTICATION_BACKENDS = (