: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(projects): show saved project tags after a page reload (#94091)
Yasene191b264d97a
diff --git a/posthog/api/project.py b/posthog/api/project.pyindex 9d97350eefa3..bcf20d264ac9 100644--- a/posthog/api/project.py+++ b/posthog/api/project.py@@ -552,11 +552,19 @@ def team_evaluation_context_suggestions_view(team: Team, request: request.Requesreturn response.Response({"success": True, "name": context_name, "hidden_from_suggestions": hidden})-class ProjectSerializer(serializers.ModelSerializer):+class ProjectSerializer(TaggedItemSerializerMixin, serializers.ModelSerializer):+ """The project as the app context serves it, which is where the frontend reads it on page load.++ projectLogic bootstraps `currentProject` from the app context and only calls the API when that+ is missing, so a field left out here is invisible to the app until something refetches.+ """++ tags = project_tags.tags_field()+class Meta:model = Project# Keep this serializer narrow; legacy Team-compatible fields live on ProjectBackwardCompatSerializer.- fields = ["id", "organization_id", "name", "product_description", "created_at", "is_pending_deletion"]+ fields = ["id", "organization_id", "name", "product_description", "created_at", "is_pending_deletion", "tags"]read_only_fields = ["id", "organization_id", "created_at", "is_pending_deletion"]diff --git a/posthog/test/test_get_context_for_template.py b/posthog/test/test_get_context_for_template.pyindex 92d6a9648a95..beeb1a8b5722 100644--- a/posthog/test/test_get_context_for_template.py+++ b/posthog/test/test_get_context_for_template.py@@ -12,6 +12,7 @@ from django.test import RequestFactoryfrom parameterized import parameterized+from posthog.api.tagged_item import set_tags_on_objectfrom posthog.models import UserHomeSettingsfrom posthog.utils import get_context_for_template@@ -72,6 +73,20 @@ class TestGetContextForTemplate(APIBaseTest):app_context = json.loads(actual["posthog_app_context"])assert app_context["homepage"] == (stored_homepage or None)+ def test_bootstraps_project_tags_into_app_context(self):+ # projectLogic reads currentProject from the app context and only calls the API when it is+ # absent, so tags missing here render an empty Tags field until something refetches.+ set_tags_on_object(["production", "eu-region"], self.team.project)++ request = RequestFactory().get("/")+ SessionMiddleware(lambda _request: HttpResponse()).process_request(request)+ request.user = self.user++ actual = get_context_for_template("layout", request)++ app_context = json.loads(actual["posthog_app_context"])+ assert sorted(app_context["current_project"]["tags"]) == ["eu-region", "production"]+@parameterized.expand([("anonymous_is_always_light", None, "light"),diff --git a/posthog/test/test_middleware.py b/posthog/test/test_middleware.pyindex 1f39ba2ba850..3dcbefd7ee28 100644--- a/posthog/test/test_middleware.py+++ b/posthog/test/test_middleware.py@@ -201,7 +201,9 @@ class TestAutoProjectMiddleware(APIBaseTest):@classmethoddef setUpTestData(cls):super().setUpTestData()- cls.base_app_num_queries = 54+ # 55, not 54: the app context serializes the project's tags, which costs one+ # indexed lookup on posthog_taggeditem per page load.+ cls.base_app_num_queries = 55# Create another team that the user does have access tocls.second_team = create_team(organization=cls.organization, name="Second Life")