Yupeek / django-rest-models

django database driver that query an RestAPI instead of a relational database
Other
64 stars 16 forks source link

Follow 301 redirect from API #69

Open vasekch opened 4 years ago

vasekch commented 4 years ago

I've successfully connected two django apps using django-rest-models 1.9.2, but I was facing following issue

When I've left everything in default as per tutorials (rest_framework and dynamic_rest on API server side and rest_models on client side) I was unable to run client application due to error:

django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:
services.ServiceBase: (rest_models.E001) the remote api does not respond to us. OPTIONS http://localhost:8000/servicebase => 301
    HINT: check the url for the remote api or the resource_path

It's because request is lacking the trailing slash. So API server responds with 301 redirect, but rest_models fail, because it's not 200 - https://github.com/Yupeek/django-rest-models/blob/3750a4b7b9bfc8c5b290f5fe4703de1ae3331cf5/rest_models/checks.py#L33. Is it possible to follow redirects somehow?

To bypass this I've changed my API - passed extra parameter to router constructor in urls.py (bellow). But I'd prefer original behavior.

...
from rest_framework import routers

router = routers.DefaultRouter(trailing_slash=False)
router.register(r'servicebase', views.ServiceBaseViewSet)

urlpatterns = [
    path('', include(router.urls)),
...

Thanks!

vasekch commented 4 years ago

Just a note.

According to requests docs it should follow 301 redirect automatically for GET, OPTIONS, POST, PUT, PATCH or DELETE. Only where you need to explicitly enable it is HEAD.

But I'm not sure how exactly we use requests and if we should change something under ApiVerbShortcutMixin in https://github.com/Yupeek/django-rest-models/blob/3750a4b7b9bfc8c5b290f5fe4703de1ae3331cf5/rest_models/backend/connexion.py#L120