: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(signals): correct invalid 'teams' ORM lookup in auto-start path (#61499)
Joshua Snyder9008942306a9
diff --git a/products/signals/backend/auto_start.py b/products/signals/backend/auto_start.pyindex 34cfced7d898..bdffccfd3bbc 100644--- a/products/signals/backend/auto_start.py+++ b/products/signals/backend/auto_start.py@@ -90,14 +90,17 @@ def _resolve_autostart_assignee(if not candidate_user_ids:return None- # Single query: fetch users who have an autonomy config, joined eagerly+ # organization__team uses the singular related_query_name for each hop, not the+ # related_name accessor (organizations/teams), which filter() won't resolve.users_with_config = {u.id: ufor u in User.objects.filter(id__in=candidate_user_ids,signal_autonomy_config__isnull=False,- teams__id=team_id,- ).select_related("signal_autonomy_config")+ organization__team=team_id,+ )+ .select_related("signal_autonomy_config")+ .distinct()}# Walk in reviewer order (most relevant first)diff --git a/products/signals/backend/test/test_auto_start.py b/products/signals/backend/test/test_auto_start.pynew file mode 100644index 000000000000..66c5c75f0384--- /dev/null+++ b/products/signals/backend/test/test_auto_start.py@@ -0,0 +1,59 @@+import pytest++from social_django.models import UserSocialAuth++from posthog.models import Organization, Team, User+from posthog.models.organization import OrganizationMembership++from products.signals.backend.auto_start import ReviewerContent, _resolve_autostart_assignee+from products.signals.backend.models import SignalUserAutonomyConfig+from products.signals.backend.report_generation.research import Priority+++def organization():+ org = Organization.objects.create(name="test-auto-start-org")+ yield org+ org.delete()+++def team(organization):+ return Team.objects.create(organization=organization, name="test-auto-start-team")+++def _create_org_member_with_github(email: str, organization: Organization, login: str) -> User:+ user = User.objects.create(email=email)+ OrganizationMembership.objects.create(user=user, organization=organization)+ UserSocialAuth.objects.create(user=user, provider="github", uid=f"github-{login}", extra_data={"login": login})+ return user+++def _reviewer(login: str) -> ReviewerContent:+ return ReviewerContent(github_login=login, github_name=None, relevant_commits=[])+++ ("autostart_priority", "report_priority", "expect_match"),+ [+ (Priority.P2, Priority.P0, True), # report priority at/above threshold → match+ (Priority.P1, Priority.P3, False), # report priority below threshold → no match+ ],+)+def test_resolve_autostart_assignee(organization, team, autostart_priority, report_priority, expect_match):+ user = _create_org_member_with_github("[email protected]", organization, "OctoCat")+ SignalUserAutonomyConfig.objects.create(user=user, autostart_priority=autostart_priority.value)++ assignee = _resolve_autostart_assignee(+ team_id=team.id,+ report_priority=report_priority,+ reviewers_content=[_reviewer("octocat")],+ team_default_priority=Priority.P0,+ )++ if expect_match:+ assert assignee is not None+ assert assignee.id == user.id+ else:+ assert assignee is None