Open
Description
Hi, so I had issues when trying to limit the data returned in the share
method called inside a middleware. I was doing something like the following:
def middleware(request):
if request.user:
share(
request,
tenants=lambda: request.user.profiles.select_related(
"organization"
).values("organization_id", "organization__name"),
)
return get_response(request)
The issue happens inside the InertiaJsonEncoder on here. As it was trying to pass a dictionary to the method model_to_dict
.
The solution I found for this was to add a custom Json encoder as explained in the documentation and do the following:
def default(self, value):
if isinstance(value, QuerySet):
return [self.default(model) for model in value]
if isinstance(value, dict):
return value
return super().default(value)
Metadata
Metadata
Assignees
Labels
No labels