: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
refactor(groups): use the generated client in relatedGroupsLogic (#128902)
Thomas Obermüller21d696058126
diff --git a/posthog/api/shared.py b/posthog/api/shared.pyindex d0a94f1c076c..f6a6f8f38175 100644--- a/posthog/api/shared.py+++ b/posthog/api/shared.py@@ -337,12 +337,25 @@ class _GroupActorTypeField(serializers.CharField):pass+class SerializedMatchedRecordingEventSerializer(serializers.Serializer):+ uuid = serializers.UUIDField(help_text="UUID of the matched event.")+ timestamp = serializers.DateTimeField(help_text="When the matched event happened.")+ window_id = serializers.CharField(help_text="ID of the browser window the event was captured in.")+++class SerializedMatchedRecordingSerializer(serializers.Serializer):+ session_id = serializers.CharField(help_text="ID of the session recording.")+ events = SerializedMatchedRecordingEventSerializer(+ many=True, help_text="Events of the recording that matched the query."+ )++class SerializedActorSerializer(serializers.Serializer):id = serializers.CharField(help_text="The person's UUID, or the group's key.")properties = serializers.DictField(child=serializers.JSONField(), help_text="The actor's properties.")created_at = serializers.DateTimeField(allow_null=True, help_text="When the actor was first seen.")- matched_recordings = serializers.ListField(- child=serializers.DictField(child=serializers.JSONField()),+ matched_recordings = SerializedMatchedRecordingSerializer(+ many=True,help_text="Recordings that matched the query. Empty unless the endpoint asks for them.",)value_at_data_point = serializers.FloatField(@@ -359,7 +372,7 @@ class SerializedPersonActorSerializer(SerializedActorSerializer):child=serializers.CharField(), help_text="The person's distinct IDs, newest first.")last_seen_at = serializers.DateTimeField(allow_null=True, help_text="When the person was last seen.")- is_identified = serializers.BooleanField(allow_null=True, help_text="Whether the person has been identified.")+ is_identified = serializers.BooleanField(help_text="Whether the person has been identified.")class SerializedGroupActorSerializer(SerializedActorSerializer):diff --git a/posthog/hogql_queries/serialized_actors.py b/posthog/hogql_queries/serialized_actors.pyindex 13ec6e82902f..671c0fbcecbc 100644--- a/posthog/hogql_queries/serialized_actors.py+++ b/posthog/hogql_queries/serialized_actors.py@@ -39,7 +39,7 @@ class SerializedPerson(CommonActor):type: Literal["person"]last_seen_at: Optional[datetime]uuid: Union[uuid.UUID, str]- is_identified: Optional[bool]+ is_identified: boolname: strdistinct_ids: list[str]matched_fields: NotRequired[list[str]]diff --git a/products/cohorts/frontend/generated/api.schemas.ts b/products/cohorts/frontend/generated/api.schemas.tsindex c6fb99fdc612..45a0eb323efe 100644--- a/products/cohorts/frontend/generated/api.schemas.ts+++ b/products/cohorts/frontend/generated/api.schemas.ts@@ -693,13 +693,27 @@ export interface CohortCalculationHistoryResponseApi {previous: string | null}+export interface SerializedMatchedRecordingEventApi {+ /** UUID of the matched event. */+ uuid: string+ /** When the matched event happened. */+ timestamp: string+ /** ID of the browser window the event was captured in. */+ window_id: string+}++export interface SerializedMatchedRecordingApi {+ /** ID of the session recording. */+ session_id: string+ /** Events of the recording that matched the query. */+ events: SerializedMatchedRecordingEventApi[]+}+/*** The actor's properties.*/export type SerializedPersonActorApiProperties = { [key: string]: unknown }-export type SerializedPersonActorApiMatchedRecordingsItem = { [key: string]: unknown }-export interface SerializedPersonActorApi {/** The person's UUID, or the group's key. */id: string@@ -711,7 +725,7 @@ export interface SerializedPersonActorApi {*/created_at: string | null/** Recordings that matched the query. Empty unless the endpoint asks for them. */- matched_recordings: SerializedPersonActorApiMatchedRecordingsItem[]+ matched_recordings: SerializedMatchedRecordingApi[]/*** The actor's value at the data point it was queried for. Null unless the query computes one.* @nullable@@ -730,11 +744,8 @@ export interface SerializedPersonActorApi {* @nullable*/last_seen_at: string | null- /**- * Whether the person has been identified.- * @nullable- */- is_identified: boolean | null+ /** Whether the person has been identified. */+ is_identified: boolean}export interface CohortPersonsResponseApi {diff --git a/products/groups/frontend/generated/api.schemas.ts b/products/groups/frontend/generated/api.schemas.tsindex 4c59994a8390..f8a781059646 100644--- a/products/groups/frontend/generated/api.schemas.ts+++ b/products/groups/frontend/generated/api.schemas.ts@@ -61,6 +61,22 @@ export interface FindGroupApi {readonly notebook: string | null}+export interface SerializedMatchedRecordingEventApi {+ /** UUID of the matched event. */+ uuid: string+ /** When the matched event happened. */+ timestamp: string+ /** ID of the browser window the event was captured in. */+ window_id: string+}++export interface SerializedMatchedRecordingApi {+ /** ID of the session recording. */+ session_id: string+ /** Events of the recording that matched the query. */+ events: SerializedMatchedRecordingEventApi[]+}+/*** Marks this actor as a person.*/@@ -76,8 +92,6 @@ export const SerializedPersonActorApiType = {*/export type SerializedPersonActorApiProperties = { [key: string]: unknown }-export type SerializedPersonActorApiMatchedRecordingsItem = { [key: string]: unknown }-export interface SerializedPersonActorApi {/** The person's UUID, or the group's key. */id: string@@ -89,7 +103,7 @@ export interface SerializedPersonActorApi {*/created_at: string | null/** Recordings that matched the query. Empty unless the endpoint asks for them. */- matched_recordings: SerializedPersonActorApiMatchedRecordingsItem[]+ matched_recordings: SerializedMatchedRecordingApi[]/*** The actor's value at the data point it was queried for. Null unless the query computes one.* @nullable@@ -108,11 +122,8 @@ export interface SerializedPersonActorApi {* @nullable*/last_seen_at: string | null- /**- * Whether the person has been identified.- * @nullable- */- is_identified: boolean | null+ /** Whether the person has been identified. */+ is_identified: boolean}/**@@ -129,8 +140,6 @@ export const SerializedGroupActorApiType = {*/export type SerializedGroupActorApiProperties = { [key: string]: unknown }-export type SerializedGroupActorApiMatchedRecordingsItem = { [key: string]: unknown }-export interface SerializedGroupActorApi {/** The person's UUID, or the group's key. */id: string@@ -142,7 +151,7 @@ export interface SerializedGroupActorApi {*/created_at: string | null/** Recordings that matched the query. Empty unless the endpoint asks for them. */- matched_recordings: SerializedGroupActorApiMatchedRecordingsItem[]+ matched_recordings: SerializedMatchedRecordingApi[]/*** The actor's value at the data point it was queried for. Null unless the query computes one.* @nullablediff --git a/products/groups/frontend/logics/relatedGroupsLogic.ts b/products/groups/frontend/logics/relatedGroupsLogic.tsindex d4b3dc541154..65527025c59b 100644--- a/products/groups/frontend/logics/relatedGroupsLogic.ts+++ b/products/groups/frontend/logics/relatedGroupsLogic.ts@@ -1,13 +1,12 @@import { MakeLogicType, connect, events, kea, key, path, props, selectors } from 'kea'import { loaders } from 'kea-loaders'-import api from 'lib/api'-import { toParams } from 'lib/utils/url'import { teamLogic } from 'scenes/teamLogic'import { ActorType } from '~/types'import type { PersonActorType } from '../../../../frontend/src/types'+import { groupsRelatedList } from '../generated/api'// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface relatedGroupsLogicValues {@@ -86,20 +85,17 @@ export const relatedGroupsLogic = kea<relatedGroupsLogicType>([relatedActors: [[] as ActorType[],{- loadRelatedActors: async () => {+ loadRelatedActors: async (): Promise<ActorType[]> => {// Abort on unmount so a slow request that fails later does not toast on the next page.const controller = new AbortController()cache.disposables.add(() => () => controller.abort(), 'relatedActorsRequest', {pauseOnPageHidden: false,})- const url = `api/projects/${values.currentTeamId}/groups/related?${toParams({- group_type_index: props.groupTypeIndex,- id: props.id,- })}`- // groupsRelatedList returns RelatedActorApi, which ActorType cannot hold:- // ~/types has is_identified non-nullable and distinct_ids optional.- // nosemgrep: prefer-codegen-api -- Legacy raw API call with a URL built at runtime and an unchecked response type. Use a generated function if one covers this endpoint.- return await api.get(url, { signal: controller.signal })+ return await groupsRelatedList(+ String(values.currentTeamId),+ { group_type_index: props.groupTypeIndex ?? undefined, id: props.id },+ { signal: controller.signal }+ )},setGroup: () => [],},diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex d57ff45462d8..79c746113fad 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -26033,6 +26033,22 @@ export namespace Schemas {count?: number | null;}+ export interface SerializedMatchedRecordingEvent {+ /** UUID of the matched event. */+ uuid: string;+ /** When the matched event happened. */+ timestamp: string;+ /** ID of the browser window the event was captured in. */+ window_id: string;+ }++ export interface SerializedMatchedRecording {+ /** ID of the session recording. */+ session_id: string;+ /** Events of the recording that matched the query. */+ events: SerializedMatchedRecordingEvent[];+ }+/*** Marks this actor as a person.*/@@ -26048,8 +26064,6 @@ export namespace Schemas {*/export type SerializedPersonActorProperties = { [key: string]: unknown };- export type SerializedPersonActorMatchedRecordingsItem = { [key: string]: unknown };-export interface SerializedPersonActor {/** The person's UUID, or the group's key. */id: string;@@ -26061,7 +26075,7 @@ export namespace Schemas {*/created_at: string | null;/** Recordings that matched the query. Empty unless the endpoint asks for them. */- matched_recordings: SerializedPersonActorMatchedRecordingsItem[];+ matched_recordings: SerializedMatchedRecording[];/*** The actor's value at the data point it was queried for. Null unless the query computes one.* @nullable@@ -26080,11 +26094,8 @@ export namespace Schemas {* @nullable*/last_seen_at: string | null;- /**- * Whether the person has been identified.- * @nullable- */- is_identified: boolean | null;+ /** Whether the person has been identified. */+ is_identified: boolean;}export interface CohortPersonsResponse {@@ -97126,8 +97137,6 @@ export namespace Schemas {*/export type SerializedGroupActorProperties = { [key: string]: unknown };- export type SerializedGroupActorMatchedRecordingsItem = { [key: string]: unknown };-export interface SerializedGroupActor {/** The person's UUID, or the group's key. */id: string;@@ -97139,7 +97148,7 @@ export namespace Schemas {*/created_at: string | null;/** Recordings that matched the query. Empty unless the endpoint asks for them. */- matched_recordings: SerializedGroupActorMatchedRecordingsItem[];+ matched_recordings: SerializedMatchedRecording[];/*** The actor's value at the data point it was queried for. Null unless the query computes one.* @nullable