Django Channels Freezes when calling internal Django-Filters API

I am using django-nextjs which required me to install Django Channels. Now this works fine until my frontend makes an API call to a DRF APIView which in turn makes an API call to Django-Filters to return a queryset. This freezes the entire server until the connection times out. Do you have an idea how this could be fixed?

My asgi.py


import os

from django.core.asgi import get_asgi_application
from django.urls import re_path, path


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.production')

django_asgi_app = get_asgi_application()

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django_nextjs.proxy import NextJSProxyHttpConsumer, NextJSProxyWebsocketConsumer

from django.conf import settings

http_routes = [re_path(r"", django_asgi_app)]
websocket_routers = []

if settings.DEBUG:
    http_routes.insert(0, re_path(r"^(?:_next|__next|next).*", NextJSProxyHttpConsumer.as_asgi()))
    websocket_routers.insert(0, path("_next/webpack-hmr", NextJSProxyWebsocketConsumer.as_asgi()))


application = ProtocolTypeRouter(
    {
        # Django's ASGI application to handle traditional HTTP and websocket requests.
        "http": URLRouter(http_routes),
        "websocket": AuthMiddlewareStack(URLRouter(websocket_routers)),
        # ...
    }
)

And here is my APIView with the internal API call to Django Filters

class SearchAPI(APIView):

    permission_classes = []
    def get(self, request, *args, **kwargs):
        received_params = {}
        
        ...

                full_request = f"{settings.BASE_URL}api/filter-recipes/?{col_to_search}__icontains={search_term}{additional_filters}"
                print('full_request: ', full_request)
                response = httpx.get(full_request)
                print('response: ', response)
                response = response.json()
                response = response["results"] if "results" in response else response
                
        ...

        return Response(json.dumps(final_response))

Everything freezes upon calling the get: 'response = httpx.get(full_request)', is there anyway I can reconfigure my asgi.py to allow for the internal API to be run and return a result?

Thanks for your input!

Back to Top