scoursen / django-softdelete

Soft delete for Django ORM, with support for undelete.
Other
376 stars 102 forks source link

`queryset = Model.objects.all()` not working using `django_tenants` #102

Open alejandro-sisteya opened 1 year ago

alejandro-sisteya commented 1 year ago

Lets suppose that I have tenant A and B, if I call the get_example endpoint with the tenant A I get the right data (tenant A data), but when I make a second request to same endpoint with tenant B I get the tenant A data.

If I refresh the server and do the same excersice in the reverse order (first tenant B and then tenand A) it happens again but returning tenant B data.

It happens with the queryset definition queryset = MyModel.objects.all() in the viewset, but if I call it again in the endpoint (like p2in the example) it works fine.

class MyModelViewSet(ModelViewSet):
    queryset = MyModel.objects.all()
    serializer_class = MyModelSerializer

    @action(detail=False)
    def get_example(self,request):
        p1=self.queryset[0]
        p2=MyModel.objects.all()[0]
        print(p1, p2)
        data = MyModelSerializer(self.queryset, many = True).data
        return Response(data)
diegooquendoopalytica commented 1 year ago

I also experienced this problem and it is just as @alejandro-sisteya defines it; On the first call to the endpoint p1 = p2, but on the second call p1 != p2.

I would think that @alejandro-sisteya and I have the same architecture in our backend; Django with DRF. In my particular case I am deploying the server on AWS Lambda with Zappa.