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(file-system): mark starred products setup done for a lazy request user (#109458)

posthog[bot]3862a1d53881
diff --git a/posthog/models/file_system/starred_products.py b/posthog/models/file_system/starred_products.py
index 3884c4d40ef0..de26a0eeff56 100644
--- a/posthog/models/file_system/starred_products.py
+++ b/posthog/models/file_system/starred_products.py
@@ -6,23 +6,23 @@ import posthoganalytics
from posthog.models.file_system.constants import DEFAULT_SURFACE, surface_q
from posthog.models.file_system.file_system_shortcut import FileSystemShortcut, lock_user_shortcuts
+from posthog.models.user import User
from posthog.products import Products
if TYPE_CHECKING:
from posthog.models.team import Team
- from posthog.models.user import User
# pinned: feature flag key, must match FEATURE_FLAGS.SIMPLE_SIDEPANEL in frontend/src/lib/constants.tsx
SIMPLE_SIDEPANEL_FLAG = "simple-sidepanel"
-def starred_products_setup_completed(user: "User") -> bool:
+def starred_products_setup_completed(user: User) -> bool:
configuration = user.ui_configuration
sidebar = configuration.get("sidebar") if isinstance(configuration, dict) else None
return isinstance(sidebar, dict) and bool(sidebar.get("starred_products_setup_completed"))
-def _simple_sidebar_enabled(user: "User", team: "Team") -> bool:
+def _simple_sidebar_enabled(user: User, team: "Team") -> bool:
return bool(
posthoganalytics.feature_enabled(
SIMPLE_SIDEPANEL_FLAG,
@@ -37,13 +37,12 @@ def _simple_sidebar_enabled(user: "User", team: "Team") -> bool:
)
-def _mark_setup_completed(user: "User") -> None:
+def _mark_setup_completed(user: User) -> None:
# Merge into the stored value under a short row lock, so a concurrent settings change is kept.
# NO KEY UPDATE is the lock the UPDATE takes anyway, and it does not block inserts of child rows.
with transaction.atomic():
- stored = (
- type(user).objects.select_for_update(no_key=True).only("ui_configuration").get(pk=user.pk).ui_configuration
- )
+ # Not type(user): request.user is a SimpleLazyObject, which has no objects manager.
+ stored = User.objects.select_for_update(no_key=True).only("ui_configuration").get(pk=user.pk).ui_configuration
configuration: dict[str, Any] = stored if isinstance(stored, dict) else {}
sidebar = configuration.get("sidebar")
user.ui_configuration = {
@@ -54,7 +53,7 @@ def _mark_setup_completed(user: "User") -> None:
user.save(update_fields=["ui_configuration"])
-def star_custom_products(user: "User", team: "Team", product_paths: list[str], *, had_custom_products: bool) -> None:
+def star_custom_products(user: User, team: "Team", product_paths: list[str], *, had_custom_products: bool) -> None:
"""Star products that were just added to a user's custom products, for simple sidebar users.
The simple sidebar shows starred products instead of custom products, so every write that adds
diff --git a/posthog/models/file_system/test/test_user_product_list.py b/posthog/models/file_system/test/test_user_product_list.py
index f20f325baaa7..45865273b2f5 100644
--- a/posthog/models/file_system/test/test_user_product_list.py
+++ b/posthog/models/file_system/test/test_user_product_list.py
@@ -1,6 +1,10 @@
+from typing import cast
+
from posthog.test.base import BaseTest
from unittest.mock import patch
+from django.utils.functional import SimpleLazyObject
+
from parameterized import parameterized
from posthog.models import ProductIntent, Team, User
@@ -99,7 +103,7 @@ class TestStarCustomProductsForSimpleSidebar(BaseTest):
with patch(
"posthog.models.file_system.starred_products.posthoganalytics.feature_enabled", return_value=flag_enabled
):
- add_default_products_for_user(user, self.team)
+ add_default_products_for_user(cast(User, SimpleLazyObject(lambda: user)), self.team)
assert set(self._starred(user)) == expected_starred
user.refresh_from_db()