You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to access objects through the related manager there are N extra queries that are performed that are unnecessary.
The problem is at __setattr__, specifically at is_val_equal_to_tenant (code).
The problen is that when we try to check the equality of val and self.tenant_object we perform another DB call to fetch the tenant.
reproduce:
fromdjango_multitenant.tests.baseimportBaseTestCasefromdjango_multitenant.tests.modelsimportProjectclassRelatedMangerTestCase(BaseTestCase):
deftest(self):
account=self.account_fr_proj_1=Project.objects.create(name="project_1", account=account)
_proj_2=Project.objects.create(name="project_2", account=account)
withself.assertNumQueries(1):
# This will fail, the actual amount of queries is 3# 1 for the SELECT query to get the projects# and then 2 more queries to fetch the tenant 1 for each projectlist(account.projects.all())
Extra queries
This query will be executed once for each related object (in this case 2 times) so when we have N related objects we will result in N extra queries.
When trying to access objects through the related manager there are N extra queries that are performed that are unnecessary.
The problem is at
__setattr__
, specifically atis_val_equal_to_tenant
(code).The problen is that when we try to check the equality of
val
andself.tenant_object
we perform another DB call to fetch the tenant.reproduce:
First expected query
Extra queries
This query will be executed once for each related object (in this case 2 times) so when we have N related objects we will result in N extra queries.The text was updated successfully, but these errors were encountered: