Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(project): stop re-fetching the team on every project response (#86817)

posthog[bot]97136d9464fb
diff --git a/posthog/api/project.py b/posthog/api/project.py
index 588410b76f01..8fbea6aa4aea 100644
--- a/posthog/api/project.py
+++ b/posthog/api/project.py
@@ -1559,10 +1559,9 @@ class ProjectViewSet(
return project
# :KLUDGE: Exposed for compatibility reasons for permission classes.
- @property
- def team(self):
- project = self.get_object()
- return project.teams.get(id=project.id)
+ @cached_property
+ def team(self) -> Team:
+ return self.get_object().passthrough_team
def perform_destroy(self, project: Project):
from ee.billing.billing_manager import BillingManager
diff --git a/products/access_control/backend/tests/test_access_control.py b/products/access_control/backend/tests/test_access_control.py
index 989a6572ad16..f957fa706dbe 100644
--- a/products/access_control/backend/tests/test_access_control.py
+++ b/products/access_control/backend/tests/test_access_control.py
@@ -1256,7 +1256,7 @@ class TestAccessControlQueryCounts(BaseAccessControlTest):
# endpoint is the only one here that doesn't already load it for other reasons.
baseline = 9
# Project access doesn't double query the object
- with self.assertNumQueries(baseline + 10):
+ with self.assertNumQueries(baseline + 9):
# We call this endpoint as we don't want to include all the extra queries that rendering the project uses
self.client.get("/api/projects/@current/is_generating_demo_data")
@@ -1307,7 +1307,7 @@ class TestAccessControlQueryCounts(BaseAccessControlTest):
# endpoint is the only one here that doesn't already load it for other reasons.
baseline = 9
# Project access doesn't double query the object
- with self.assertNumQueries(baseline + 10):
+ with self.assertNumQueries(baseline + 9):
# We call this endpoint as we don't want to include all the extra queries that rendering the project uses
self.client.get("/api/projects/@current/is_generating_demo_data")