diff --git a/corehq/apps/api/odata/serializers.py b/corehq/apps/api/odata/serializers.py index 2e2ffbf8ad83f..4cb2e80e1eaf1 100644 --- a/corehq/apps/api/odata/serializers.py +++ b/corehq/apps/api/odata/serializers.py @@ -41,12 +41,14 @@ def to_json(self, data, options=None): domain = data.pop('domain', None) config_id = data.pop('config_id', None) api_path = data.pop('api_path', None) + api_version = data.pop('api_version', None) table_id = data.pop('table_id', None) - assert all([domain, config_id, api_path]), [domain, config_id, api_path] + assert all([domain, config_id, api_path, api_version]), \ + [domain, config_id, api_path, api_version] context_urlname = self.metadata_url - context_url_args = [domain, config_id] + context_url_args = [domain, api_version, config_id] if table_id > 0: context_urlname = self.table_metadata_url context_url_args.append(table_id) diff --git a/corehq/apps/api/odata/views.py b/corehq/apps/api/odata/views.py index cdc37bd4d0683..930ef4d3a747a 100644 --- a/corehq/apps/api/odata/views.py +++ b/corehq/apps/api/odata/views.py @@ -71,13 +71,13 @@ class ODataCaseServiceView(BaseODataView): urlname = 'odata_case_service_from_export_instance' table_urlname = 'odata_case_service_from_export_instance_table' - def get(self, request, domain, config_id, **kwargs): + def get(self, request, domain, api_version, config_id, **kwargs): table_id = int(kwargs.get('table_id', 0)) config = get_document_or_404(CaseExportInstance, domain, config_id) if raise_odata_permissions_issues(request.couch_user, domain, config): raise Http404() urlname = ODataCaseMetadataView.urlname - url_args = [domain, config_id] + url_args = [domain, api_version, config_id] if table_id > 0: urlname = ODataCaseMetadataView.table_urlname url_args.append(table_id) @@ -126,13 +126,13 @@ class ODataFormServiceView(BaseODataView): urlname = 'odata_form_service_from_export_instance' table_urlname = 'odata_form_service_from_export_instance_table' - def get(self, request, domain, config_id, **kwargs): + def get(self, request, domain, api_version, config_id, **kwargs): table_id = int(kwargs.get('table_id', 0)) config = get_document_or_404(FormExportInstance, domain, config_id) if raise_odata_permissions_issues(request.couch_user, domain, config): raise Http404() urlname = ODataFormMetadataView.urlname - url_args = [domain, config_id] + url_args = [domain, api_version, config_id] if table_id > 0: urlname = ODataFormMetadataView.table_urlname url_args.append(table_id) diff --git a/corehq/apps/api/resources/v0_5.py b/corehq/apps/api/resources/v0_5.py index 30482d7680bf0..1e866b0f9ce07 100644 --- a/corehq/apps/api/resources/v0_5.py +++ b/corehq/apps/api/resources/v0_5.py @@ -1029,6 +1029,7 @@ def create_response(self, request, data, response_class=HttpResponse, **response_kwargs): data['domain'] = request.domain data['api_path'] = request.path + data['api_version'] = self.api_name # Avoids storing these properties on the class instance which protects against the possibility of # concurrent requests making conflicting updates to properties data['config_id'] = request.resolver_match.kwargs['config_id'] diff --git a/corehq/apps/api/urls.py b/corehq/apps/api/urls.py index 3a3be7e0b6100..f234faca80bec 100644 --- a/corehq/apps/api/urls.py +++ b/corehq/apps/api/urls.py @@ -122,8 +122,8 @@ def versioned_apis(api_list): urlpatterns = [ - path('v0.5/odata/', include(odata_urlpatterns)), - path('odata/v1/', include(odata_urlpatterns)), + url(r'(?Pv0.5)/odata/', include(odata_urlpatterns)), + url(r'odata/(?Pv1)/', include(odata_urlpatterns)), url(r'(?Pv0.5)/messaging-event/$', messaging_events, name="api_messaging_event_list"), url(r'(?Pv0.5)/messaging-event/(?P\d+)/$',