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(customer-analytics): show churned ignored accounts in lifecycle filters (#109423)

Arthur Moreira de Deus4770fc0d0dc1
diff --git a/products/customer_analytics/backend/facade/api.py b/products/customer_analytics/backend/facade/api.py
index 250c714dc0d1..9a27cfa6add7 100644
--- a/products/customer_analytics/backend/facade/api.py
+++ b/products/customer_analytics/backend/facade/api.py
@@ -3251,10 +3251,36 @@ def _validate_account_table_definitions(
return custom_property_display_types
-def _filters_account_table_field(
- filters: tuple[contracts.AccountTableFilter, ...], field: contracts.AccountTableField
-) -> bool:
- return any(isinstance(filter_, contracts.AccountTableFieldFilter) and filter_.field == field for filter_ in filters)
+LIFECYCLE_ACCOUNT_TABLE_FIELDS = frozenset(
+ {contracts.AccountTableField.CHURNED_AT, contracts.AccountTableField.IGNORED_AT}
+)
+
+
+def _selects_lifecycle_accounts(filters: tuple[contracts.AccountTableFilter, ...]) -> bool:
+ return any(
+ isinstance(filter_, contracts.AccountTableFieldFilter)
+ and filter_.field in LIFECYCLE_ACCOUNT_TABLE_FIELDS
+ and filter_.operator != contracts.AccountTableFieldOperator.IS_NOT_SET
+ for filter_ in filters
+ )
+
+
+def _filter_out_hidden_lifecycle_accounts(
+ queryset: QuerySet[Account],
+ filters: tuple[contracts.AccountTableFilter, ...],
+ *,
+ include_churned: bool,
+ include_ignored: bool,
+) -> QuerySet[Account]:
+ # Track Rules skip churned accounts, so a churned account keeps its ignored_at. Hiding either
+ # state here would drop accounts that a churned or ignored filter asks for.
+ if _selects_lifecycle_accounts(filters):
+ return queryset
+ if not include_churned:
+ queryset = queryset.filter(churned_at__isnull=True)
+ if not include_ignored:
+ queryset = queryset.filter(ignored_at__isnull=True)
+ return queryset
def _apply_account_table_filters(
@@ -3289,16 +3315,12 @@ def _apply_account_table_filters(
if filter_groups:
matching_groups = Q()
for group in filter_groups:
- group_query = queryset
- branch_filters = filters + group
- if not include_churned and not _filters_account_table_field(
- branch_filters, contracts.AccountTableField.CHURNED_AT
- ):
- group_query = group_query.filter(churned_at__isnull=True)
- if not include_ignored and not _filters_account_table_field(
- branch_filters, contracts.AccountTableField.IGNORED_AT
- ):
- group_query = group_query.filter(ignored_at__isnull=True)
+ group_query = _filter_out_hidden_lifecycle_accounts(
+ queryset,
+ filters + group,
+ include_churned=include_churned,
+ include_ignored=include_ignored,
+ )
group_query = apply_account_filters(
group_query,
team_id=team_id,
@@ -3445,10 +3467,9 @@ def query_accounts_metrics(
accounts = _accounts_queryset(team_id, user_access_control)
if not filter_groups:
- if not include_churned and not _filters_account_table_field(filters, contracts.AccountTableField.CHURNED_AT):
- accounts = accounts.filter(churned_at__isnull=True)
- if not include_ignored and not _filters_account_table_field(filters, contracts.AccountTableField.IGNORED_AT):
- accounts = accounts.filter(ignored_at__isnull=True)
+ accounts = _filter_out_hidden_lifecycle_accounts(
+ accounts, filters, include_churned=include_churned, include_ignored=include_ignored
+ )
accounts = _apply_account_table_filters(
accounts,
team_id=team_id,
@@ -3539,10 +3560,9 @@ def query_accounts_table(
queryset = _accounts_queryset(team_id, user_access_control)
if not filter_groups:
- if not include_churned and not _filters_account_table_field(filters, contracts.AccountTableField.CHURNED_AT):
- queryset = queryset.filter(churned_at__isnull=True)
- if not include_ignored and not _filters_account_table_field(filters, contracts.AccountTableField.IGNORED_AT):
- queryset = queryset.filter(ignored_at__isnull=True)
+ queryset = _filter_out_hidden_lifecycle_accounts(
+ queryset, filters, include_churned=include_churned, include_ignored=include_ignored
+ )
queryset = _apply_account_table_filters(
queryset,
team_id=team_id,
diff --git a/products/customer_analytics/backend/hogql_queries/test/test_accounts_table_query_runner.py b/products/customer_analytics/backend/hogql_queries/test/test_accounts_table_query_runner.py
index 1599af69de71..6d9a0fa04e60 100644
--- a/products/customer_analytics/backend/hogql_queries/test/test_accounts_table_query_runner.py
+++ b/products/customer_analytics/backend/hogql_queries/test/test_accounts_table_query_runner.py
@@ -655,11 +655,9 @@ class TestAccountsTableQueryRunner(BaseTest):
self, _name: str, lifecycle_field: AccountsTableAccountField
) -> None:
timestamp = datetime(2026, 1, 1, tzinfo=UTC)
- churned_at = timestamp if lifecycle_field == AccountsTableAccountField.CHURNED_AT else None
- ignored_at = timestamp if lifecycle_field == AccountsTableAccountField.IGNORED_AT else None
create_account(team_id=self.team.id, name="Shared active")
- create_account(team_id=self.team.id, name="Shared hidden", churned_at=churned_at, ignored_at=ignored_at)
- create_account(team_id=self.team.id, name="Target hidden", churned_at=churned_at, ignored_at=ignored_at)
+ create_account(team_id=self.team.id, name="Shared hidden", churned_at=timestamp, ignored_at=timestamp)
+ create_account(team_id=self.team.id, name="Target hidden", churned_at=timestamp, ignored_at=timestamp)
groups = [
[
AccountsTableAccountFieldFilter(
@@ -809,7 +807,7 @@ class TestAccountsTableQueryRunner(BaseTest):
operator=AccountsTableAccountFieldOperator.IS_SET,
)
],
- {"Active ignored"},
+ {"Active ignored", "Churned ignored"},
),
(
"churned",
@@ -819,7 +817,17 @@ class TestAccountsTableQueryRunner(BaseTest):
operator=AccountsTableAccountFieldOperator.IS_SET,
)
],
- {"Churned tracked"},
+ {"Churned tracked", "Churned ignored"},
+ ),
+ (
+ "not_ignored",
+ [
+ AccountsTableAccountFieldFilter(
+ field=AccountsTableAccountField.IGNORED_AT,
+ operator=AccountsTableAccountFieldOperator.IS_NOT_SET,
+ )
+ ],
+ {"Active tracked"},
),
(
"churned_and_ignored",
diff --git a/products/customer_analytics/frontend/components/Accounts/AGENTS.md b/products/customer_analytics/frontend/components/Accounts/AGENTS.md
index 425ce71dc9ea..087737283e2f 100644
--- a/products/customer_analytics/frontend/components/Accounts/AGENTS.md
+++ b/products/customer_analytics/frontend/components/Accounts/AGENTS.md
@@ -118,7 +118,7 @@ The config persists per view via `ColumnConfiguration.properties.column_display`
**Account filters** live in `AccountsFilterGroups`, using a selected `LemonButton` with a spaced accent-colored count and compact `LemonCard` groups without headings inside a bordered filter area. Restored filters start collapsed. The shared `PropertyFilterButton` resolves relationship values through `membersLogic`, matching the member picker. The empty state shows only the shared Filter trigger; completing the first condition expands the editor. Removing the first group promotes the next branch via `removeFirstAccountFilterGroup`. Collapse is local presentation state and does not change saved filters. They reuse `PropertyFilters` for each OR branch; filters within a branch use AND. The first branch keeps the legacy flat `accountFilters` state, and further branches live in `accountFilterGroups`. Each branch offers native Account fields, Account relationships, and Account custom properties. Search, tags, assignment status, and tile filters remain global AND restrictions. The query planner sends multiple nonempty branches as `filterGroups` to the Postgres runner. Saved views, shared URL hashes, and session drafts persist the branches; legacy flat views keep their AND behavior.
Relationship options come from the team's relationship definitions. They use the shared member picker and support matching a specific member, excluding a member, and checking whether a relationship is assigned.
-Native fields cover names, external and connection IDs, created and updated timestamps, and the `churned_at` and `ignored_at` lifecycle timestamps. Text fields support exact, negative, contains, and set operators. Timestamp fields support exact date, before, after, and set operators. A lifecycle timestamp filter includes that normally hidden state before applying its predicate, so `Ignored at is set` returns ignored accounts while an unfiltered list still hides them.
+Native fields cover names, external and connection IDs, created and updated timestamps, and the `churned_at` and `ignored_at` lifecycle timestamps. Text fields support exact, negative, contains, and set operators. Timestamp fields support exact date, before, after, and set operators. A lifecycle timestamp filter with any operator except `is not set` lifts both default hides before applying its predicate, so `Ignored at is set` returns every ignored account, churned ones included, while an unfiltered list still hides them. Track Rules skip churned accounts, so a churned account keeps its `ignored_at`.
Custom property options come from `accountsColumnConfigLogic.customPropertyTaxonomicOptions` via `optionsFromProp`. The filter `key` is the stable definition ID, and the definition name rides on the filter's `label` for display.
Operator sets honor each field's type because `accountsColumnConfigLogic` seeds `propertyDefinitionsModel` under `PropertyDefinitionType.Account` and `PropertyDefinitionType.AccountCustomProperty`. The dropdown is narrowed to operators the Postgres runner supports. Regex and negative regex operators are not available.
`accountsTableQuery.ts` translates all three filter kinds into typed query filters. The backend filters relationships through active assignments, native model or JSON fields directly, and custom properties through storage chosen from the definition type. Negative operators include accounts where the value is unset. Invalid native combinations and deleted or incompatible custom properties are omitted rather than changing query engines.