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.

chore(devex): rename dataclasses to domain-concept names (#76163)

Arno Hillenf82374ceb1dc
diff --git a/ee/api/test/test_event_definition.py b/ee/api/test/test_event_definition.py
index 71cd96a52da5..3ca32ed99aed 100644
--- a/ee/api/test/test_event_definition.py
+++ b/ee/api/test/test_event_definition.py
@@ -11,7 +11,7 @@ import dateutil.parser
from parameterized import parameterized
from rest_framework import status
-from posthog.api.test.test_event_definition import EventData, capture_event
+from posthog.api.test.test_event_definition import EventFixture, capture_event
from posthog.api.test.test_organization import create_organization
from posthog.api.test.test_team import create_team
from posthog.api.test.test_user import create_user
@@ -48,7 +48,7 @@ class TestEventDefinitionEnterpriseAPI(APIBaseTest):
for event_definition in cls.EXPECTED_EVENT_DEFINITIONS:
EnterpriseEventDefinition.objects.create(name=event_definition["name"], team_id=cls.demo_team.pk)
capture_event(
- event=EventData(
+ event=EventFixture(
event=event_definition["name"],
team_id=cls.demo_team.pk,
distinct_id="abc",
diff --git a/posthog/api/test/test_event_definition.py b/posthog/api/test/test_event_definition.py
index 4d0b018cbb75..93667d1bc2ff 100644
--- a/posthog/api/test/test_event_definition.py
+++ b/posthog/api/test/test_event_definition.py
@@ -45,7 +45,7 @@ class TestEventDefinitionAPI(APIBaseTest):
for event_definition in cls.EXPECTED_EVENT_DEFINITIONS:
create_event_definitions(event_definition, team_id=cls.demo_team.pk)
capture_event(
- event=EventData(
+ event=EventFixture(
event=event_definition["name"],
team_id=cls.demo_team.pk,
distinct_id="abc",
@@ -645,7 +645,7 @@ class TestEventDefinitionExcludeStale(APIBaseTest):
@dataclasses.dataclass
-class EventData:
+class EventFixture:
"""
Little utility struct for creating test event data
"""
@@ -657,7 +657,7 @@ class EventData:
properties: dict[str, Any]
-def capture_event(event: EventData):
+def capture_event(event: EventFixture):
"""
Creates an event, given an event dict. Currently just puts this data
directly into clickhouse, but could be created via api to get better parity
diff --git a/posthog/management/commands/generate_random_product_tours.py b/posthog/management/commands/generate_random_product_tours.py
index 24af74fb2e9f..ffea6ed9c3ec 100644
--- a/posthog/management/commands/generate_random_product_tours.py
+++ b/posthog/management/commands/generate_random_product_tours.py
@@ -15,7 +15,7 @@ from posthog.clickhouse.client import sync_execute
from posthog.constants import PRODUCT_TOUR_TARGETING_FLAG_PREFIX
from posthog.models import Team, User
from posthog.models.event.sql import BULK_INSERT_EVENT_SQL
-from posthog.persons_seed import PersonData, fetch_recent_persons_with_distinct_id
+from posthog.persons_seed import SeedPerson, fetch_recent_persons_with_distinct_id
from products.feature_flags.backend.models.feature_flag import FeatureFlag
from products.product_tours.backend.models import ProductTour
@@ -201,7 +201,7 @@ class Command(BaseCommand):
self,
event_name: str,
properties: dict[str, Any],
- person_data: PersonData,
+ person_data: SeedPerson,
timestamp: Any,
team: Team,
index: int,
@@ -271,7 +271,7 @@ class Command(BaseCommand):
return insert, params
def generate_tour_events(
- self, tour: ProductTour, team: Team, num_events: int, days_back: int, persons_data: list[PersonData]
+ self, tour: ProductTour, team: Team, num_events: int, days_back: int, persons_data: list[SeedPerson]
) -> dict[str, int]:
"""Generate product tour events.
@@ -450,7 +450,7 @@ class Command(BaseCommand):
return
# Fetch real persons if events are requested
- persons_data: list[PersonData] = []
+ persons_data: list[SeedPerson] = []
if num_events > 0:
persons_data = fetch_recent_persons_with_distinct_id(team.id, limit=100)
if persons_data:
diff --git a/posthog/management/commands/generate_random_surveys.py b/posthog/management/commands/generate_random_surveys.py
index 9a8103ba8dfc..67001e5e5731 100644
--- a/posthog/management/commands/generate_random_surveys.py
+++ b/posthog/management/commands/generate_random_surveys.py
@@ -11,7 +11,7 @@ from django.utils import timezone
from posthog.clickhouse.client import sync_execute
from posthog.models import Team, User
from posthog.models.event.sql import BULK_INSERT_EVENT_SQL
-from posthog.persons_seed import PersonData, fetch_recent_persons_with_distinct_id
+from posthog.persons_seed import SeedPerson, fetch_recent_persons_with_distinct_id
from posthog.settings.data_stores import CLICKHOUSE_CLUSTER
from products.surveys.backend.models import Survey
@@ -806,7 +806,7 @@ class Command(BaseCommand):
self,
event_name: str,
properties: dict[str, Any],
- person_data: PersonData,
+ person_data: SeedPerson,
timestamp: Any,
team: Team,
index: int,
@@ -884,7 +884,7 @@ class Command(BaseCommand):
team: Team,
num_responses: int,
days_back: int,
- persons_data: list[PersonData],
+ persons_data: list[SeedPerson],
with_trace_ids: bool = False,
real_trace_ids: list[str] | None = None,
) -> tuple[int, int, int]:
@@ -1103,7 +1103,7 @@ class Command(BaseCommand):
total_dismissed = 0
# Fetch real persons from the database if responses are requested
- persons_data: list[PersonData] = []
+ persons_data: list[SeedPerson] = []
if num_responses > 0:
persons_data = fetch_recent_persons_with_distinct_id(team.id, limit=100)
if persons_data:
diff --git a/posthog/persons_seed.py b/posthog/persons_seed.py
index 3a67eb9b4a62..a25f70f09663 100644
--- a/posthog/persons_seed.py
+++ b/posthog/persons_seed.py
@@ -177,7 +177,7 @@ def update_seed_person(
@dataclasses.dataclass
-class PersonData:
+class SeedPerson:
"""A person fetched from the persons database for dev/seed event generation."""
distinct_id: str
@@ -186,7 +186,7 @@ class PersonData:
created_at: Any
-def fetch_recent_persons_with_distinct_id(team_id: int, *, limit: int = 50) -> list[PersonData]:
+def fetch_recent_persons_with_distinct_id(team_id: int, *, limit: int = 50) -> list[SeedPerson]:
"""Return up to ``limit`` most-recently-created persons that have a distinct ID.
Each person is paired with one of its distinct IDs; the inner lateral join drops
@@ -203,6 +203,6 @@ def fetch_recent_persons_with_distinct_id(team_id: int, *, limit: int = 50) -> l
cursor.execute(query, {"team_id": team_id, "limit": limit})
rows = cursor.fetchall()
return [
- PersonData(person_uuid=str(row[0]), properties=row[1] or {}, created_at=row[2], distinct_id=row[3])
+ SeedPerson(person_uuid=str(row[0]), properties=row[1] or {}, created_at=row[2], distinct_id=row[3])
for row in rows
]
diff --git a/posthog/temporal/ingestion_acceptance_test/runner.py b/posthog/temporal/ingestion_acceptance_test/runner.py
index e04986e17187..95af1bf77d76 100644
--- a/posthog/temporal/ingestion_acceptance_test/runner.py
+++ b/posthog/temporal/ingestion_acceptance_test/runner.py
@@ -18,7 +18,7 @@ logger = structlog.get_logger(__name__)
@dataclass
-class RunningTestInfo:
+class RunningTestSnapshot:
"""Snapshot of a running test with its current pending poll description."""
name: str
@@ -45,7 +45,7 @@ class RunningTests:
with self._lock:
return sorted(self._tests.values())
- def snapshot_with_polls(self, client: PostHogClient) -> list[RunningTestInfo]:
+ def snapshot_with_polls(self, client: PostHogClient) -> list[RunningTestSnapshot]:
"""Snapshot running tests correlated with their pending poll descriptions.
Joins by thread ID: each test runs in its own thread, and the client
@@ -55,7 +55,7 @@ class RunningTests:
tests_by_tid = dict(self._tests)
polls_by_tid = client.pending_polls_snapshot()
return [
- RunningTestInfo(name=name, pending_poll=polls_by_tid.get(tid))
+ RunningTestSnapshot(name=name, pending_poll=polls_by_tid.get(tid))
for tid, name in sorted(tests_by_tid.items(), key=lambda x: x[1])
]
diff --git a/posthog/temporal/ingestion_acceptance_test/slack.py b/posthog/temporal/ingestion_acceptance_test/slack.py
index c7834e5acae3..510f3ade8871 100644
--- a/posthog/temporal/ingestion_acceptance_test/slack.py
+++ b/posthog/temporal/ingestion_acceptance_test/slack.py
@@ -7,7 +7,7 @@ import structlog
from .config import Config
from .results import TestSuiteResult
-from .runner import RunningTestInfo
+from .runner import RunningTestSnapshot
logger = structlog.get_logger(__name__)
@@ -116,12 +116,12 @@ def _build_context_block(config: Config, result: TestSuiteResult) -> dict[str, A
}
-def send_slack_timeout_notification(config: Config, running_tests: list[RunningTestInfo] | None = None) -> bool:
+def send_slack_timeout_notification(config: Config, running_tests: list[RunningTestSnapshot] | None = None) -> bool:
"""Send a timeout notification to Slack via incoming webhook.
Args:
config: Configuration containing the Slack webhook URL.
- running_tests: List of RunningTestInfo with test names and their pending
+ running_tests: List of RunningTestSnapshot with test names and their pending
poll descriptions (what each test was waiting for in ClickHouse).
Returns:
diff --git a/posthog/temporal/tests/ingestion_acceptance_test/test_runner.py b/posthog/temporal/tests/ingestion_acceptance_test/test_runner.py
index 32e7be5649b1..43f47fb1a411 100644
--- a/posthog/temporal/tests/ingestion_acceptance_test/test_runner.py
+++ b/posthog/temporal/tests/ingestion_acceptance_test/test_runner.py
@@ -6,8 +6,8 @@ from unittest.mock import MagicMock, patch
from posthog.temporal.ingestion_acceptance_test.config import Config
from posthog.temporal.ingestion_acceptance_test.runner import (
AcceptanceTest,
- RunningTestInfo,
RunningTests,
+ RunningTestSnapshot,
TestContext,
run_tests,
)
@@ -203,16 +203,16 @@ class TestSnapshotWithPolls:
{100: "TestA::test_one", 200: "TestB::test_two"},
{100: "event UUID 'abc-123'", 200: "person with distinct_id 'xyz-456'"},
[
- RunningTestInfo("TestA::test_one", "event UUID 'abc-123'"),
- RunningTestInfo("TestB::test_two", "person with distinct_id 'xyz-456'"),
+ RunningTestSnapshot("TestA::test_one", "event UUID 'abc-123'"),
+ RunningTestSnapshot("TestB::test_two", "person with distinct_id 'xyz-456'"),
],
),
(
{100: "TestA::test_one", 200: "TestB::test_two"},
{100: "event UUID 'abc-123'"},
[
- RunningTestInfo("TestA::test_one", "event UUID 'abc-123'"),
- RunningTestInfo("TestB::test_two", None),
+ RunningTestSnapshot("TestA::test_one", "event UUID 'abc-123'"),
+ RunningTestSnapshot("TestB::test_two", None),
],
),
({}, {}, []),
@@ -223,7 +223,7 @@ class TestSnapshotWithPolls:
self,
tests_by_tid: dict[int, str],
polls_by_tid: dict[int, str],
- expected: list[RunningTestInfo],
+ expected: list[RunningTestSnapshot],
) -> None:
rt = RunningTests()
rt._tests = tests_by_tid
diff --git a/posthog/temporal/tests/ingestion_acceptance_test/test_slack.py b/posthog/temporal/tests/ingestion_acceptance_test/test_slack.py
index 550bbd6924b3..aec62c0fbaf1 100644
--- a/posthog/temporal/tests/ingestion_acceptance_test/test_slack.py
+++ b/posthog/temporal/tests/ingestion_acceptance_test/test_slack.py
@@ -3,7 +3,7 @@ from unittest.mock import MagicMock, patch
from posthog.temporal.ingestion_acceptance_test.config import Config
from posthog.temporal.ingestion_acceptance_test.results import TestResult, TestSuiteResult
-from posthog.temporal.ingestion_acceptance_test.runner import RunningTestInfo
+from posthog.temporal.ingestion_acceptance_test.runner import RunningTestSnapshot
from posthog.temporal.ingestion_acceptance_test.slack import send_slack_notification, send_slack_timeout_notification
@@ -239,8 +239,8 @@ class TestSendSlackTimeoutNotification:
[
(
[
- RunningTestInfo(name="TestAlias::test_alias", pending_poll="person with distinct_id 'abc-123'"),
- RunningTestInfo(name="TestMerge::test_merge", pending_poll="events for person 'person-789'"),
+ RunningTestSnapshot(name="TestAlias::test_alias", pending_poll="person with distinct_id 'abc-123'"),
+ RunningTestSnapshot(name="TestMerge::test_merge", pending_poll="events for person 'person-789'"),
],
[
"TestAlias::test_alias",
@@ -251,7 +251,7 @@ class TestSendSlackTimeoutNotification:
[],
),
(
- [RunningTestInfo(name="TestBasic::test_capture", pending_poll=None)],
+ [RunningTestSnapshot(name="TestBasic::test_capture", pending_poll=None)],
["TestBasic::test_capture"],
["waiting for"],
),
@@ -263,7 +263,7 @@ class TestSendSlackTimeoutNotification:
self,
mock_post: MagicMock,
config: Config,
- running_tests: list[RunningTestInfo],
+ running_tests: list[RunningTestSnapshot],
expected_in_text: list[str],
not_expected_in_text: list[str],
) -> None:
diff --git a/posthog/views.py b/posthog/views.py
index e4ae85bfbdbe..89e6d266bbb7 100644
--- a/posthog/views.py
+++ b/posthog/views.py
@@ -273,7 +273,7 @@ MAX_VALUE_DISPLAY_LENGTH = 200
@dataclass
-class RedisKeyInfo:
+class RedisKeySnapshot:
key: str
type: str
ttl: timedelta | int
@@ -302,7 +302,7 @@ def truncate_value(value, max_length: int = MAX_VALUE_DISPLAY_LENGTH) -> str:
return str_value[:max_length] + "..."
-def get_redis_key_info(key: bytes, redis_client) -> RedisKeyInfo:
+def get_redis_key_info(key: bytes, redis_client) -> RedisKeySnapshot:
redis_key = key.decode("utf-8")
redis_type = redis_client.type(redis_key).decode("utf8")
redis_ttl = redis_client.ttl(redis_key)
@@ -327,7 +327,7 @@ def get_redis_key_info(key: bytes, redis_client) -> RedisKeyInfo:
full_value = str(value)
is_truncated = len(full_value) > MAX_VALUE_DISPLAY_LENGTH
- return RedisKeyInfo(
+ return RedisKeySnapshot(
key=redis_key,
type=redis_type,
ttl=redis_ttl,