: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
feat(data-modeling): record why a run rebuilt the whole table (#98276)
Jovan Sakovicaeed2ecbda25
diff --git a/posthog/temporal/data_modeling/activities/materialize_view.py b/posthog/temporal/data_modeling/activities/materialize_view.pyindex 7ca722a65f4a..5480cca65d5a 100644--- a/posthog/temporal/data_modeling/activities/materialize_view.py+++ b/posthog/temporal/data_modeling/activities/materialize_view.py@@ -1098,6 +1098,7 @@ async def materialize_view_activity(inputs: MaterializeViewInputs) -> Materializobjects.job.run_mode = (DataModelingJob.RunMode.INCREMENTAL if plan.incremental else DataModelingJob.RunMode.FULL_REFRESH)+ objects.job.full_refresh_reason = None if plan.incremental else plan.reasonawait database_sync_to_async_pool(objects.job.save)()person_property_sink = await _build_person_property_sink(diff --git a/posthog/temporal/tests/data_modeling/test_materialize_view_incremental.py b/posthog/temporal/tests/data_modeling/test_materialize_view_incremental.pyindex 51fda7dd96f1..029846a95bc0 100644--- a/posthog/temporal/tests/data_modeling/test_materialize_view_incremental.py+++ b/posthog/temporal/tests/data_modeling/test_materialize_view_incremental.py@@ -140,6 +140,7 @@ class TestIncrementalMaterialization:# The runs UI reads the mode off the job to explain what its row count means.await database_sync_to_async(ajob.refresh_from_db)()assert ajob.run_mode == "full_refresh"+ assert ajob.full_refresh_reason == "first run"async def test_second_run_updates_touched_rows_and_leaves_the_rest(self, activity_environment, ateam, anode, asaved_query, ajob, bucket_name, adag@@ -164,6 +165,7 @@ class TestIncrementalMaterialization:await database_sync_to_async(ajob.refresh_from_db)()assert ajob.run_mode == "incremental"+ assert ajob.full_refresh_reason is Noneasync def test_replaying_a_run_does_not_duplicate_rows(self, activity_environment, ateam, anode, asaved_query, ajob, bucket_name, adagdiff --git a/products/data_modeling/backend/migrations/0038_datamodelingjob_full_refresh_reason.py b/products/data_modeling/backend/migrations/0038_datamodelingjob_full_refresh_reason.pynew file mode 100644index 000000000000..cc1aa1fe4180--- /dev/null+++ b/products/data_modeling/backend/migrations/0038_datamodelingjob_full_refresh_reason.py@@ -0,0 +1,17 @@+# Generated by Django 5.2.17 on 2026-09-10 11:04++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("data_modeling", "0037_alter_datawarehousesavedquery_folder_and_more"),+ ]++ operations = [+ migrations.AddField(+ model_name="datamodelingjob",+ name="full_refresh_reason",+ field=models.CharField(blank=True, max_length=200, null=True),+ ),+ ]diff --git a/products/data_modeling/backend/migrations/max_migration.txt b/products/data_modeling/backend/migrations/max_migration.txtindex 462b54823c85..ecd7b4a539d1 100644--- a/products/data_modeling/backend/migrations/max_migration.txt+++ b/products/data_modeling/backend/migrations/max_migration.txt@@ -1 +1 @@-0037_alter_datawarehousesavedquery_folder_and_more+0038_datamodelingjob_full_refresh_reasondiff --git a/products/data_modeling/backend/models/data_modeling_job.py b/products/data_modeling/backend/models/data_modeling_job.pyindex be141fa078a2..1f74539d94d8 100644--- a/products/data_modeling/backend/models/data_modeling_job.py+++ b/products/data_modeling/backend/models/data_modeling_job.py@@ -33,6 +33,7 @@ class DataModelingJob(CreatedMetaFields, UpdatedMetaFields, UUIDTModel):engine = models.CharField(max_length=20, choices=Engine, default=Engine.CLICKHOUSE)# Null: recorded before run modes existed, or the run failed before the write plan resolved.run_mode = models.CharField(max_length=20, choices=RunMode, null=True, blank=True)+ full_refresh_reason = models.CharField(max_length=200, null=True, blank=True)rows_materialized = models.IntegerField(default=0)error = models.TextField(null=True, blank=True)workflow_id = models.CharField(max_length=400, null=True, blank=True)diff --git a/products/data_warehouse/backend/presentation/views/data_modeling_job.py b/products/data_warehouse/backend/presentation/views/data_modeling_job.pyindex 0a35a9c2d03e..443e5a06b680 100644--- a/products/data_warehouse/backend/presentation/views/data_modeling_job.py+++ b/products/data_warehouse/backend/presentation/views/data_modeling_job.py@@ -27,6 +27,12 @@ class DataModelingJobSerializer(serializers.ModelSerializer):"the rows synced. Null for runs from before modes were recorded, or that failed before ""the plan resolved.",)+ full_refresh_reason = serializers.CharField(+ read_only=True,+ allow_null=True,+ help_text="Why this run rebuilt the whole table instead of updating only new rows, for "+ "example first run, definition changed, or table missing. Null when the run was incremental.",+ )class Meta:model = DataModelingJob@@ -35,6 +41,7 @@ class DataModelingJobSerializer(serializers.ModelSerializer):"saved_query_id","status","run_mode",+ "full_refresh_reason","rows_materialized","error","created_at",diff --git a/products/data_warehouse/frontend/generated/api.schemas.ts b/products/data_warehouse/frontend/generated/api.schemas.tsindex 1d6aeb01dbe8..05688fdb9952 100644--- a/products/data_warehouse/frontend/generated/api.schemas.ts+++ b/products/data_warehouse/frontend/generated/api.schemas.ts@@ -47,6 +47,11 @@ export interface DataModelingJobApi {* * `full_refresh` - Full refresh* * `incremental` - Incremental */readonly run_mode: DataModelingJobRunModeEnumApi | null+ /**+ * Why this run rebuilt the whole table instead of updating only new rows, for example first run, definition changed, or table missing. Null when the run was incremental.+ * @nullable+ */+ readonly full_refresh_reason: string | nullreadonly rows_materialized: number/** @nullable */readonly error: string | nulldiff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 44d7ddda555e..15c10e38ac27 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -22602,6 +22602,11 @@ export namespace Schemas {* * `full_refresh` - Full refresh* * `incremental` - Incremental */readonly run_mode: DataModelingJobRunModeEnum | null;+ /**+ * Why this run rebuilt the whole table instead of updating only new rows, for example first run, definition changed, or table missing. Null when the run was incremental.+ * @nullable+ */+ readonly full_refresh_reason: string | null;readonly rows_materialized: number;/** @nullable */readonly error: string | null;