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.

feat(data-warehouse): partition testrail source on created_on (#69991)

Tom Owers22063f4dfd76
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/SOURCES.md b/products/warehouse_sources/backend/temporal/data_imports/sources/SOURCES.md
index 32ec7e43970d..d7a21441c482 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/SOURCES.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/SOURCES.md
@@ -799,7 +799,6 @@ doesn't conflict with concurrent PRs.
- telli
- tempo
- terra_api
-- testrail
- thinkific_courses
- thrive_learning
- ticketmaster
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/testrail/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/testrail/settings.py
index b75169bfe204..fa9e35beb2e8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/testrail/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/testrail/settings.py
@@ -43,6 +43,11 @@ class TestrailEndpointConfig:
# TestRail record IDs are instance-global (case C123 / run R45 identifiers are unique across
# projects), so `id` is a safe table-wide primary key even for fan-out endpoints.
primary_keys: list[str] = field(default_factory=lambda: ["id"])
+ # Stable UNIX-timestamp field to bucket the Delta table on (datetime partitioning). Never the
+ # incremental cursor when that is `updated_after` — a partition key must not move, so `cases`
+ # partitions on `created_on` even though it syncs incrementally on `updated_on`. Only set for
+ # endpoints whose records carry `created_on`; the rest stay unpartitioned.
+ partition_key: Optional[str] = None
TESTRAIL_ENDPOINTS: dict[str, TestrailEndpointConfig] = {
@@ -87,6 +92,7 @@ TESTRAIL_ENDPOINTS: dict[str, TestrailEndpointConfig] = {
# get_cases filters server-side on updated_after (UNIX timestamp against updated_on).
incremental_param="updated_after",
incremental_fields=_epoch_incremental_field("updated_on"),
+ partition_key="created_on",
),
"milestones": TestrailEndpointConfig(
name="milestones",
@@ -109,6 +115,7 @@ TESTRAIL_ENDPOINTS: dict[str, TestrailEndpointConfig] = {
# (see _runs_rows).
incremental_param="created_after",
incremental_fields=_epoch_incremental_field("created_on"),
+ partition_key="created_on",
),
"plans": TestrailEndpointConfig(
name="plans",
@@ -118,6 +125,7 @@ TESTRAIL_ENDPOINTS: dict[str, TestrailEndpointConfig] = {
paginated=True,
incremental_param="created_after",
incremental_fields=_epoch_incremental_field("created_on"),
+ partition_key="created_on",
),
"tests": TestrailEndpointConfig(
name="tests",
@@ -137,6 +145,7 @@ TESTRAIL_ENDPOINTS: dict[str, TestrailEndpointConfig] = {
# TestRail, so a created_on cursor is a genuine incremental sync.
incremental_param="created_after",
incremental_fields=_epoch_incremental_field("created_on"),
+ partition_key="created_on",
),
"statuses": TestrailEndpointConfig(
name="statuses",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/testrail/testrail.py b/products/warehouse_sources/backend/temporal/data_imports/sources/testrail/testrail.py
index 7ae834380741..b5ac3dd23621 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/testrail/testrail.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/testrail/testrail.py
@@ -508,6 +508,12 @@ def testrail_source(
primary_keys=config.primary_keys,
partition_count=1,
partition_size=1,
+ # Endpoints that carry a stable `created_on` bucket by week; TestRail timestamps are UNIX
+ # epoch integers, which datetime partitioning coerces via fromtimestamp. `created_on` never
+ # moves, so partitions are not rewritten on later syncs (unlike an `updated_on` key would).
+ partition_mode="datetime" if config.partition_key else None,
+ partition_format="week" if config.partition_key else None,
+ partition_keys=[config.partition_key] if config.partition_key else None,
# Fan-out across projects/suites/runs means rows never arrive globally time-ordered, so
# incremental endpoints declare "desc": the watermark commits only once the whole sync
# completes instead of checkpointing after every batch.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/testrail/tests/test_testrail.py b/products/warehouse_sources/backend/temporal/data_imports/sources/testrail/tests/test_testrail.py
index e89eeb3b03c5..d1c7b277e812 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/testrail/tests/test_testrail.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/testrail/tests/test_testrail.py
@@ -383,8 +383,19 @@ class TestTestrailSourceResponse:
assert response.primary_keys == ["id"]
# Fan-out rows never arrive globally time-ordered, so incremental endpoints must commit
# their watermark only at end of sync (desc); asc would corrupt it on mid-sync restarts.
- expected_sort = "desc" if TESTRAIL_ENDPOINTS[endpoint].incremental_param else "asc"
- assert response.sort_mode == expected_sort
+ config = TESTRAIL_ENDPOINTS[endpoint]
+ assert response.sort_mode == ("desc" if config.incremental_param else "asc")
+ # Only endpoints carrying a stable `created_on` partition; the rest stay unpartitioned so a
+ # missing/moving key never becomes a datetime bucket. `created_on` (not the `updated_on`
+ # cursor) keeps partitions from being rewritten on later syncs.
+ if config.partition_key:
+ assert config.partition_key == "created_on"
+ assert response.partition_mode == "datetime"
+ assert response.partition_format == "week"
+ assert response.partition_keys == ["created_on"]
+ else:
+ assert response.partition_mode is None
+ assert response.partition_keys is None
class TestCheckAccess: