: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(admin): don't require test_account_filters on team inline (#67030)
Marce Coll6e43831ae552
diff --git a/posthog/admin/inlines/team_inline.py b/posthog/admin/inlines/team_inline.pyindex f56d55b13e11..077d141b3332 100644--- a/posthog/admin/inlines/team_inline.py+++ b/posthog/admin/inlines/team_inline.py@@ -2,13 +2,16 @@ from django.utils.html import format_htmlfrom django_admin_inline_paginator.admin import TabularInlinePaginated-from posthog.admin.admins.team_admin import TeamAdmin+from posthog.admin.admins.team_admin import TeamAdmin, TeamAdminFormfrom posthog.models import Teamclass TeamInline(TabularInlinePaginated):extra = 0model = Team+ # The default ModelForm requires test_account_filters, so an empty [] is rejected as required and+ # blocks disabling the org. TeamAdminForm makes it optional (and rejects non-list values).+ form = TeamAdminFormper_page = 20pagination_key = "page-team"show_change_link = Truediff --git a/posthog/admin/test_team_admin.py b/posthog/admin/test_team_admin.pyindex 3b83be30c15e..1f87bfee894d 100644--- a/posthog/admin/test_team_admin.py+++ b/posthog/admin/test_team_admin.py@@ -9,11 +9,13 @@ from unittest.mock import patchfrom django.contrib.admin.sites import AdminSitefrom django.contrib.messages.storage.fallback import FallbackStoragefrom django.core.exceptions import PermissionDenied+from django.forms import ModelFormfrom django.test import RequestFactoryfrom parameterized import parameterizedfrom posthog.admin.admins.team_admin import TeamAdmin+from posthog.admin.inlines.team_inline import TeamInlinefrom posthog.llm.gateway_internal_client import (AIGatewayInternalError,AIGatewayNotConfigured,@@ -21,6 +23,7 @@ from posthog.llm.gateway_internal_client import (LedgerEntry,Wallet,)+from posthog.models import Organizationfrom posthog.models.activity_logging.activity_log import ActivityLogfrom posthog.models.team.team import Team@@ -621,3 +624,29 @@ class TestTeamAdminFormOverspendAllowance(BaseTest):child = Team.objects.create(organization=self.organization, name="child env", parent_team=self.team)with self.assertRaises(ValidationError):self._form(Decimal("5"), instance=child).clean_llm_gateway_overspend_allowance_usd()+++class TestTeamInlineForm(BaseTest):+ def _inline_form(self, data: dict | None = None) -> ModelForm:+ request = RequestFactory().get("/")+ request.user = self.user+ form_class = TeamInline(Organization, AdminSite()).get_formset(request).form+ return form_class(data=data, instance=self.team) if data is not None else form_class()++ def test_test_account_filters_is_not_required(self) -> None:+ # Guards org-disable: the field must stay optional or an empty [] re-blocks the org save.+ assert self._inline_form().fields["test_account_filters"].required is False++ def test_blank_test_account_filters_normalizes_to_empty_list(self) -> None:+ # Blank input cleans to None; it must normalize to [] so it never hits the NOT NULL column as None.+ form = self._inline_form({"test_account_filters": ""})+ form.is_valid() # only this field's outcome matters; other inline fields are absent+ assert "test_account_filters" not in form.errors+ assert form.cleaned_data["test_account_filters"] == []++ @parameterized.expand([("object", "{}"), ("nested_object", '{"key": "email"}'), ("string", '"oops"')])+ def test_non_list_test_account_filters_is_rejected(self, _name: str, raw: str) -> None:+ # required=False must not let non-list JSON through onto the field.+ form = self._inline_form({"test_account_filters": raw})+ form.is_valid()+ assert "test_account_filters" in form.errors