Hello, I have a module in my application that implements a model with a hierarchical structure. I am using a custom url converter that parses a series of slugs and returns a list of those objects:
from module.models import Object
class slugGraph:
regex = r"([-a-zA-Z0-9_]/?)+"
def to_python(self, value):
ret = []
for slug in value.split("/"):
try:
ret.append(object.objects.get(slug=slug))
except Object.DoesNotExist:
raise ValueError
return ret
def to_url(self, value):
ret = ""
for x in value:
ret += x.slug
ret += "/"
ret = ret[:-1] # removes last slash
return ret
This works perfectly well on the development web server, but when I try to deploy the code via ASGI, I get the following error:
SynchronousOnlyOperation - You cannot call this from an async context - use a thread or sync_to_async.
The application errors out on the line:
ret.append(object.objects.get(slug=slug))
Is using converters to return an object like this impossible when deploying using ASGI?
Thank you for your time and I you can help me