: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
chore(migrations): retire deployed data migration tests (#111500)
Paul D'Ambra1e2ecc27bbe5
diff --git a/ee/api/test/test_subscription.py b/ee/api/test/test_subscription.pyindex 24ffef0a5dba..87c2cd8a43d7 100644--- a/ee/api/test/test_subscription.py+++ b/ee/api/test/test_subscription.py@@ -50,7 +50,6 @@ from products.exports.backend.temporal.subscriptions.types import (from products.product_analytics.backend.facade.models import Insightfrom ee.api.test.base import APILicensedTest-from ee.tasks.subscriptions.slack_subscriptions import get_slack_integration_for_teamfrom ee.tasks.subscriptions.subscription_utils import MAX_INSIGHTSfrom ee.tasks.subscriptions.teams_subscriptions import TEAMS_WEBHOOK_URL_ERROR, TEAMS_WEBHOOK_URL_MASKED_ERRORfrom ee.tasks.test.subscriptions.subscriptions_test_factory import create_subscription@@ -1613,68 +1612,6 @@ class TestSubscriptionTemporal(APILicensedTest):assert mock_client.start_workflow.call_count == 3- def test_backfill_picks_same_integration_as_delivery(self):- """The data migration must assign the lowest-id Slack integration- per team, matching get_slack_integration_for_team behavior."""- import importlib-- from django.apps import apps- from django.utils import timezone-- migration = importlib.import_module("posthog.migrations.1041_backfill_subscription_integration")-- # Team 1: two slack integrations- integration_a = Integration.objects.create(team=self.team, kind="slack", config={"a": 1})- Integration.objects.create(team=self.team, kind="slack", config={"b": 2})-- # Team 2: its own slack integration (higher id than team 1's)- other_team = Team.objects.create(organization=self.organization, name="Other Team")- other_insight = Insight.objects.create(- filters=Filter(data=self.insight_filter_dict).to_dict(),- team=other_team,- created_by=self.user,- )- other_integration = Integration.objects.create(team=other_team, kind="slack", config={"c": 3})-- sub_team1 = Subscription.objects.create(- team=self.team,- insight=self.insight,- target_type="slack",- target_value="C1234|#general",- frequency="weekly",- interval=1,- start_date=timezone.now(),- title="Slack Sub Team 1",- )- sub_team2 = Subscription.objects.create(- team=other_team,- insight=other_insight,- target_type="slack",- target_value="C5678|#alerts",- frequency="weekly",- interval=1,- start_date=timezone.now(),- title="Slack Sub Team 2",- )-- # Run the actual backfill migration function- migration.backfill_subscription_integration(apps, None)-- sub_team1.refresh_from_db()- sub_team2.refresh_from_db()-- # Each subscription got its own team's integration, not a global lowest id- assert sub_team1.integration_id == integration_a.id- assert sub_team2.integration_id == other_integration.id-- # And both match what get_slack_integration_for_team would return- delivery_team1 = get_slack_integration_for_team(self.team.id)- delivery_team2 = get_slack_integration_for_team(other_team.id)- assert delivery_team1 is not None- assert delivery_team2 is not None- assert sub_team1.integration_id == delivery_team1.id- assert sub_team2.integration_id == delivery_team2.id-def test_list_subscriptions_defaults_to_newest_created_first(self):r1 = self._create_subscription(title="Older")assert r1.status_code == status.HTTP_201_CREATEDdiff --git a/ee/migrations/test/test_migration_0058.py b/ee/migrations/test/test_migration_0058.pydeleted file mode 100644index 154c100ead4c..000000000000--- a/ee/migrations/test/test_migration_0058.py+++ /dev/null@@ -1,68 +0,0 @@-import importlib--from posthog.test.base import BaseTest--from django.apps import apps as current_apps-from django.db.migrations.loader import MigrationLoader-from django.db.migrations.operations.fields import RenameField--from parameterized import parameterized--from posthog.models.identity_provider_config import IdentityProviderConfig-from posthog.models.organization_domain import OrganizationDomain-from posthog.models.user import User--from ee.models.scim_provisioned_user import SCIMProvisionedUser--migration_module = importlib.import_module("ee.migrations.0058_backfill_scim_provisioned_user_config")-backfill_scim_provisioned_user_config = migration_module.backfill_scim_provisioned_user_config---class FakeSchemaEditor:- class connection:- alias = "default"---def apps_before_the_rename():- # posthog.1316 renames the field, and the squashes leave this backfill free to run on either- # side of it. The current state with that one rename undone is the other side.- state = MigrationLoader(connection=None).project_state()- RenameField("organizationdomain", "_identity_provider_config", "identity_provider_config").state_forwards(- "posthog", state- )- return state.apps---class TestBackfillScimProvisionedUserConfig(BaseTest):- def _domain(self, domain: str, config: IdentityProviderConfig) -> OrganizationDomain:- return OrganizationDomain.objects.create(- organization=self.organization, domain=domain, _identity_provider_config=config- )-- def _record(self, user: User, domain: OrganizationDomain) -> SCIMProvisionedUser:- return SCIMProvisionedUser.objects.create(- user=user,- organization_domain=domain,- identity_provider=SCIMProvisionedUser.IdentityProvider.OKTA,- username=user.email,- )-- @parameterized.expand([("before_the_rename",), ("after_the_rename",)])- def test_claims_records_keyed_on_a_domain(self, case):- config = IdentityProviderConfig.objects.create(organization=self.organization, scim_enabled=True)- first_domain = self._domain("one.example.com", config)- second_domain = self._domain("two.example.com", config)-- claimable = self._record(self.user, first_domain)- duplicate_user = User.objects.create_and_join(self.organization, "[email protected]", None)- oldest_of_the_duplicates = self._record(duplicate_user, first_domain)- newest_of_the_duplicates = self._record(duplicate_user, second_domain)-- apps = apps_before_the_rename() if case == "before_the_rename" else current_apps- backfill_scim_provisioned_user_config(apps, FakeSchemaEditor())-- for record in (claimable, oldest_of_the_duplicates, newest_of_the_duplicates):- record.refresh_from_db()- assert claimable.identity_provider_config_id == config.id- assert oldest_of_the_duplicates.identity_provider_config_id == config.id- assert newest_of_the_duplicates.identity_provider_config_id is Nonediff --git a/ee/migrations/test/test_migration_0060.py b/ee/migrations/test/test_migration_0060.pydeleted file mode 100644index b95c66473159..000000000000--- a/ee/migrations/test/test_migration_0060.py+++ /dev/null@@ -1,118 +0,0 @@-import importlib--from posthog.test.base import BaseTest--from django.apps import apps--from parameterized import parameterized--from products.access_control.backend.models.access_control import AccessControl-from products.access_control.backend.models.role import Role--migration_module = importlib.import_module("ee.migrations.0060_backfill_evaluation_access_control")-backfill_evaluation_access_control = migration_module.backfill_evaluation_access_control---class TestBackfillEvaluationAccessControl(BaseTest):- def _scope_kwargs(self, case):- role = (- Role.objects.create(name="Engineering", organization=self.organization) if case == "role_scoped" else None- )- return {- "organization_member": self.organization_membership if case == "member_scoped" else None,- "role": role,- }-- @parameterized.expand(- [- ("member_scoped",),- ("role_scoped",),- ("org_default",),- ]- )- def test_backfills_resource_wide_row(self, case):- scope_kwargs = self._scope_kwargs(case)-- AccessControl.objects.create(- team=self.team, resource="llm_analytics", resource_id=None, access_level="viewer", **scope_kwargs- )-- backfill_evaluation_access_control(apps, None)-- backfilled = AccessControl.objects.filter(resource="evaluation", team=self.team, **scope_kwargs).first()- assert backfilled is not None- assert backfilled.access_level == "viewer"-- def test_does_not_touch_other_resources(self):- AccessControl.objects.create(- team=self.team,- resource="dataset",- resource_id=None,- access_level="editor",- organization_member=self.organization_membership,- )-- backfill_evaluation_access_control(apps, None)-- assert not AccessControl.objects.filter(resource="evaluation").exists()-- def test_ignores_object_scoped_llm_analytics_rows(self):- AccessControl.objects.create(- team=self.team,- resource="llm_analytics",- resource_id="123",- access_level="editor",- organization_member=self.organization_membership,- )-- backfill_evaluation_access_control(apps, None)-- assert not AccessControl.objects.filter(resource="evaluation").exists()-- def test_does_not_overwrite_existing_row(self):- AccessControl.objects.create(- team=self.team,- resource="llm_analytics",- resource_id=None,- access_level="editor",- organization_member=self.organization_membership,- )- AccessControl.objects.create(- team=self.team,- resource="evaluation",- resource_id=None,- access_level="none",- organization_member=self.organization_membership,- )-- backfill_evaluation_access_control(apps, None)-- rows = AccessControl.objects.filter(resource="evaluation", organization_member=self.organization_membership)-- assert rows.count() == 1- row = rows.first()- assert row is not None- assert row.access_level == "none"-- @parameterized.expand(- [- ("member_scoped",),- ("role_scoped",),- ("org_default",),- ]- )- def test_idempotent_on_repeat_run(self, case):- # organization_member/role are nullable, and Postgres unique constraints treat NULLs as- # distinct, so the org_default (both-None) case would silently duplicate on a second run- # if the migration ever stopped looking up the existing row before creating one.- scope_kwargs = self._scope_kwargs(case)-- AccessControl.objects.create(- team=self.team, resource="llm_analytics", resource_id=None, access_level="viewer", **scope_kwargs- )-- backfill_evaluation_access_control(apps, None)- backfill_evaluation_access_control(apps, None)-- rows = AccessControl.objects.filter(resource="evaluation", team=self.team, **scope_kwargs)- assert rows.count() == 1diff --git a/ee/migrations/test/test_migration_0064.py b/ee/migrations/test/test_migration_0064.pydeleted file mode 100644index 4f23956105e6..000000000000--- a/ee/migrations/test/test_migration_0064.py+++ /dev/null@@ -1,125 +0,0 @@-from importlib import import_module--from posthog.test.base import BaseTest--from django.apps import apps-from django.db import connection--from parameterized import parameterized--from posthog.models import IdentityProviderConfig, LinkedIdentityProviderConfig, OrganizationDomain--from ee.models.scim_provisioned_user import SCIMProvisionedUser-from ee.models.scim_request_log import SCIMRequestLog---class TestSplitIdentityProviderConfigScopes(BaseTest):- def test_splits_only_present_features_and_preserves_links_and_scim_records(self) -> None:- domain = OrganizationDomain.objects.create(organization=self.organization, domain="example.com")- source = IdentityProviderConfig.objects.create(- organization=self.organization,- name="Example IdP",- domain_scope="selected",- saml_entity_id="partial-saml",- oidc_client_id="partial-oidc",- oidc_credentials={"client_secret": "example-secret"},- scim_bearer_token="hashed-token",- id_jag_jwks_url="https://example.com/keys",- )- LinkedIdentityProviderConfig.objects.create(organization_domain=domain, identity_provider_config=source)- record = SCIMProvisionedUser.objects.create(- user=self.user,- identity_provider_config=source,- identity_provider="okta",- username="example",- )- log = SCIMRequestLog.objects.create(- identity_provider_config=source,- request_method="GET",- request_path="/scim/v2/example/Users",- response_status=200,- )- empty = IdentityProviderConfig.objects.create(organization=self.organization)- already_scoped = IdentityProviderConfig.objects.create(organization=self.organization, config_scope="saml")-- migration = import_module("ee.migrations.0064_split_identity_provider_config_scopes")- migration.split_identity_provider_config_scopes(apps, connection.schema_editor())-- assert not IdentityProviderConfig.objects.filter(pk__in=[source.pk, empty.pk]).exists()- assert IdentityProviderConfig.objects.filter(pk=already_scoped.pk).exists()- configs = {- config.config_scope: config- for config in IdentityProviderConfig.objects.filter(organization=self.organization).exclude(- pk=already_scoped.pk- )- }- assert set(configs) == {"saml", "oidc", "scim", "xaa"}- assert configs["saml"].saml_entity_id == "partial-saml"- assert str(configs["saml"].saml_relay_state) == str(source.saml_relay_state)- assert not configs["saml"].oidc_client_id- assert configs["oidc"].oidc_client_id == "partial-oidc"- assert configs["oidc"].oidc_credentials == {"client_secret": "example-secret"}- assert configs["scim"].scim_bearer_token == "hashed-token"- assert str(configs["scim"].scim_slug) == str(source.scim_slug)- assert not configs["scim"].saml_entity_id- assert configs["xaa"].id_jag_jwks_url == "https://example.com/keys"- assert all(- config.name == source.name and config.domain_scope == source.domain_scope for config in configs.values()- )- assert set(- LinkedIdentityProviderConfig.objects.filter(organization_domain=domain).values_list(- "identity_provider_config_id", flat=True- )- ) == {config.pk for config in configs.values()}- record.refresh_from_db()- log.refresh_from_db()- assert record.identity_provider_config_id == configs["scim"].pk- assert log.identity_provider_config_id == configs["scim"].pk-- def test_generated_identifiers_do_not_create_empty_scopes(self) -> None:- source = IdentityProviderConfig.objects.create(- organization=self.organization,- saml_acs_url="https://example.com/acs",- )-- migration = import_module("ee.migrations.0064_split_identity_provider_config_scopes")- migration.split_identity_provider_config_scopes(apps, connection.schema_editor())-- assert not IdentityProviderConfig.objects.filter(pk=source.pk).exists()- assert list(- IdentityProviderConfig.objects.filter(organization=self.organization).values_list("config_scope", flat=True)- ) == ["saml"]-- @parameterized.expand([("provisioned_user",), ("request_log",)])- def test_disabled_scim_preserves_record_attribution(self, record_type: str) -> None:- source = IdentityProviderConfig.objects.create(- organization=self.organization,- scim_enabled=False,- scim_bearer_token=None,- )- record: SCIMProvisionedUser | SCIMRequestLog- if record_type == "provisioned_user":- record = SCIMProvisionedUser.objects.create(- user=self.user,- identity_provider_config=source,- identity_provider="okta",- username="example",- )- else:- record = SCIMRequestLog.objects.create(- identity_provider_config=source,- request_method="GET",- request_path="/scim/v2/example/Users",- response_status=200,- )-- migration = import_module("ee.migrations.0064_split_identity_provider_config_scopes")- migration.split_identity_provider_config_scopes(apps, connection.schema_editor())-- assert not IdentityProviderConfig.objects.filter(pk=source.pk).exists()- scoped = IdentityProviderConfig.objects.get(organization=self.organization, config_scope="scim")- assert str(scoped.scim_slug) == str(source.scim_slug)- assert scoped.scim_enabled is False- assert scoped.scim_bearer_token is None- record.refresh_from_db()- assert record.identity_provider_config_id == scoped.pkdiff --git a/posthog/clickhouse/test/test_0064.py b/posthog/clickhouse/test/test_0064.pydeleted file mode 100644index 5050a6458bde..000000000000--- a/posthog/clickhouse/test/test_0064.py+++ /dev/null@@ -1,42 +0,0 @@-# ruff: noqa-import importlib--from posthog.test.base import BaseTest, ClickhouseDestroyTablesMixin, _create_event-from posthog.clickhouse.client import sync_execute--module = importlib.import_module("posthog.clickhouse.migrations.0064_materialize_elements_chain")--add_columns_to_required_tables = module.add_columns_to_required_tables--from posthog.models.element.element import Element, chain_to_elements---def _create_events(team, elements_chains=[]):- for ec in elements_chains:- _create_event(- team=team,- distinct_id="1",- event="$autocapture",- elements=chain_to_elements(ec),- )---class Test0064(ClickhouseDestroyTablesMixin):- def test_filtering(self):- add_columns_to_required_tables("")- _create_events(- self.team,- [- # should be extracted- 'a:attr_id="easy_text"',- 'a:attr_id="cutoff"text"',- 'a:something="else"attr_id="text3"',- 'a:attr_id="text4";b:attr_id="text5"',- # don't extract- 'a:differentattr_id="text2"',- ],- )- resp = sync_execute("select elements_chain_ids from events where elements_chain_ids[1] != ''")- self.assertCountEqual(- [row[0] for row in resp], [["easy_text"], ["cutoff"], ["text3"], ["text4", "text5"]], resp- )diff --git a/products/alerts/backend/test/test_migration_0009_redact_webhook_names.py b/products/alerts/backend/test/test_migration_0009_redact_webhook_names.pydeleted file mode 100644index 0afb067a4636..000000000000--- a/products/alerts/backend/test/test_migration_0009_redact_webhook_names.py+++ /dev/null@@ -1,80 +0,0 @@-from typing import Any--from posthog.test.base import TestMigrations--ALERT_FILTERS = {- "source": "internal-events",- "events": [{"id": "$logs_alert_firing", "type": "events"}],- "properties": [{"key": "alert_id", "value": "alert-1", "operator": "exact", "type": "event"}],-}-LEAKED_NAME = "Logs — Errors (firing) → Webhook https://hooks.example.com/services/T000/B000/s3cr3t"-LEAKED_SEGMENT = LEAKED_NAME.replace("/", "\\/")-REDACTED_NAME = "Logs — Errors (firing) → Webhook hooks.example.com"---class TestRedactWebhookUrlsInDestinationNames(TestMigrations):- app = "alerts"- migrate_from = "0008_platformalert_firing_started_at_and_uuid7_pk"- migrate_to = "0009_redact_webhook_urls_in_destination_names"-- def setUpBeforeMigration(self, apps: Any) -> None:- HogFunction = apps.get_model("cdp", "HogFunction")- FileSystem = apps.get_model("posthog", "FileSystem")- FileSystemShortcut = apps.get_model("posthog", "FileSystemShortcut")-- def make(name: str, filters: dict) -> Any:- return HogFunction.objects.create(- team_id=self.team.id,- type="internal_destination",- template_id="template-webhook",- name=name,- filters=filters,- hog="return",- )-- self.alert_webhook = make(LEAKED_NAME, ALERT_FILTERS)- self.file_entry = FileSystem.objects.create(- team_id=self.team.id,- path="Unfiled/Destinations/" + LEAKED_SEGMENT,- depth=3,- type="hog_function/internal_destination",- ref=str(self.alert_webhook.id),- )- self.shortcut = FileSystemShortcut.objects.create(- team_id=self.team.id,- user_id=self.user.id,- path=LEAKED_SEGMENT,- type="hog_function/internal_destination",- ref=str(self.alert_webhook.id),- )- self.user_webhook_name = "My webhook https://hooks.example.com/services/T000/B000/mine"- self.user_webhook = make(self.user_webhook_name, {"source": "internal-events", "events": []})-- self.quoted_webhook = make(- "Logs — Errors (firing) → Webhook https://hooks.example.com/hook?token='s3cr3t",- ALERT_FILTERS,- )- self.quoted_in_alert_name = make(- "Logs — https://hooks.example.com/h?t='s3cr3t (firing) → Webhook https://hooks.example.com/other",- ALERT_FILTERS,- )-- def test_only_alert_managed_webhook_names_are_redacted(self) -> None:- assert self.apps is not None- HogFunction = self.apps.get_model("cdp", "HogFunction")- FileSystem = self.apps.get_model("posthog", "FileSystem")- FileSystemShortcut = self.apps.get_model("posthog", "FileSystemShortcut")-- assert HogFunction.objects.get(id=self.alert_webhook.id).name == REDACTED_NAME- assert FileSystem.objects.get(id=self.file_entry.id).path == "Unfiled/Destinations/" + REDACTED_NAME- # A starred destination keeps its own copy of the name.- assert FileSystemShortcut.objects.get(id=self.shortcut.id).path == REDACTED_NAME- assert HogFunction.objects.get(id=self.user_webhook.id).name == self.user_webhook_name- # An apostrophe is legal in a URL query, and treating it as the end of the URL used to- # leave everything after it in the name. That holds for the URL the builder appended and- # for one the alert's own name carried, which has text after it.- assert HogFunction.objects.get(id=self.quoted_webhook.id).name == REDACTED_NAME- assert (- HogFunction.objects.get(id=self.quoted_in_alert_name.id).name- == "Logs — hooks.example.com (firing) → Webhook hooks.example.com"- )diff --git a/products/canvas/backend/tests/test_migration_mask_canvas_comment_activity.py b/products/canvas/backend/tests/test_migration_mask_canvas_comment_activity.pydeleted file mode 100644index 88401da9c239..000000000000--- a/products/canvas/backend/tests/test_migration_mask_canvas_comment_activity.py+++ /dev/null@@ -1,39 +0,0 @@-from typing import Any--from posthog.test.base import TestMigrations---class TestMaskCanvasCommentActivity(TestMigrations):- migrate_from = "0020_alter_canvas_channel"- migrate_to = "0021_mask_canvas_comment_activity"-- def setUpBeforeMigration(self, apps: Any) -> None:- Comment = apps.get_model("posthog", "Comment")- ActivityLog = apps.get_model("posthog", "ActivityLog")- canvas_root = Comment.objects.create(team_id=self.team.id, scope="desktop_canvas", item_id="canvas-1")- insight_root = Comment.objects.create(team_id=self.team.id, scope="Insight", item_id="insight-1")-- def log(scope: str, item_id: str, content: str) -> None:- ActivityLog.objects.create(- team_id=self.team.id,- scope=scope,- activity="commented",- item_id=item_id,- detail={"changes": [{"type": "Comment", "field": "content", "action": "created", "after": content}]},- )-- log("desktop_canvas", "canvas-1", "canvas root text")- log("Comment", str(canvas_root.id), "canvas reply text")- log("Insight", "insight-1", "insight root text")- log("Comment", str(insight_root.id), "insight reply text")-- def test_masks_only_canvas_comment_text(self) -> None:- assert self.apps is not None- ActivityLog = self.apps.get_model("posthog", "ActivityLog")-- contents = sorted(- row.detail["changes"][0]["after"]- for row in ActivityLog.objects.filter(team_id=self.team.id, activity="commented")- )-- assert contents == ["insight reply text", "insight root text", "masked", "masked"]diff --git a/products/replay_vision/backend/tests/test_quota.py b/products/replay_vision/backend/tests/test_quota.pyindex e9ffcda57d35..33623e42c78c 100644--- a/products/replay_vision/backend/tests/test_quota.py+++ b/products/replay_vision/backend/tests/test_quota.py@@ -380,91 +380,6 @@ class TestComputeScannerBudget(_VisionQuotaTestCase):assert budget.credits_used >= 15-class TestBackfillUsageScannerId(_VisionQuotaTestCase):- def test_backfills_null_scanner_ids_only_where_the_observation_still_exists(self) -> None:- import uuid- import importlib-- from django.apps import apps as django_apps- from django.db import connection-- observation = self._make_observation(status=ObservationStatus.SUCCEEDED, completed_at=timezone.now())- ReplayObservationUsage.objects.filter(observation_id=observation.id).update(scanner_id=None)- orphan = ReplayObservationUsage.objects.create(- organization_id=self.organization.id,- observation_id=uuid.uuid4(),- observation_created_at=timezone.now(),- )-- migration = importlib.import_module("products.replay_vision.backend.migrations.0070_backfill_usage_scanner_id")- with connection.schema_editor(atomic=False) as schema_editor:- migration.backfill_scanner_id(django_apps, schema_editor)-- assert ReplayObservationUsage.objects.get(observation_id=observation.id).scanner_id == self.scanner.id- orphan.refresh_from_db()- assert orphan.scanner_id is None-- def test_backfill_attributes_all_receipts_across_batches(self) -> None:- import uuid- import importlib-- from django.apps import apps as django_apps- from django.db import connection-- observations = [- self._make_observation(status=ObservationStatus.SUCCEEDED, completed_at=timezone.now()) for _ in range(3)- ]- ReplayObservationUsage.objects.filter(observation_id__in=[o.id for o in observations]).update(scanner_id=None)- orphan = ReplayObservationUsage.objects.create(- organization_id=self.organization.id,- observation_id=uuid.uuid4(),- observation_created_at=timezone.now(),- )-- migration = importlib.import_module("products.replay_vision.backend.migrations.0070_backfill_usage_scanner_id")- # BATCH_SIZE=1 forces one keyset iteration per receipt, exercising the pagination loop.- with patch.object(migration, "BATCH_SIZE", 1):- with connection.schema_editor(atomic=False) as schema_editor:- migration.backfill_scanner_id(django_apps, schema_editor)-- for observation in observations:- assert ReplayObservationUsage.objects.get(observation_id=observation.id).scanner_id == self.scanner.id- orphan.refresh_from_db()- assert orphan.scanner_id is None---class TestRebackfillUsageScannerId(_VisionQuotaTestCase):- def test_rebackfill_attributes_receipts_across_batches_and_leaves_orphans_null(self) -> None:- import uuid- import importlib-- from django.apps import apps as django_apps- from django.db import connection-- observations = [- self._make_observation(status=ObservationStatus.SUCCEEDED, completed_at=timezone.now()) for _ in range(3)- ]- ReplayObservationUsage.objects.filter(observation_id__in=[o.id for o in observations]).update(scanner_id=None)- orphan = ReplayObservationUsage.objects.create(- organization_id=self.organization.id,- observation_id=uuid.uuid4(),- observation_created_at=timezone.now(),- )-- migration = importlib.import_module(- "products.replay_vision.backend.migrations.0073_rebackfill_usage_scanner_id"- )- # BATCH_SIZE=1 forces one keyset iteration per receipt, exercising the pagination loop.- with patch.object(migration, "BATCH_SIZE", 1):- with connection.schema_editor(atomic=False) as schema_editor:- migration.rebackfill_scanner_id(django_apps, schema_editor)-- for observation in observations:- assert ReplayObservationUsage.objects.get(observation_id=observation.id).scanner_id == self.scanner.id- orphan.refresh_from_db()- assert orphan.scanner_id is None--class TestScannerBudgetBlocked(SimpleTestCase):@parameterized.expand([diff --git a/products/signals/backend/test/test_backfill_report_actionability.py b/products/signals/backend/test/test_backfill_report_actionability.pyindex e8c9e909571c..62b677e33a4d 100644--- a/products/signals/backend/test/test_backfill_report_actionability.py+++ b/products/signals/backend/test/test_backfill_report_actionability.py@@ -1,11 +1,7 @@import json-import importlib-from datetime import UTC, datetimefrom posthog.test.base import BaseTest-from unittest.mock import patch-from django.apps import appsfrom django.core.management import call_commandfrom products.signals.backend.models import SignalReport, SignalReportArtefact@@ -48,68 +44,3 @@ class TestBackfillReportActionability(BaseTest):assert self._cached(drifted) == ("requires_human_input", True)assert self._cached(never_judged) == (None, None)-- def _judgment(self, report: SignalReport, *, content: str, created_at: datetime) -> None:- artefact = SignalReportArtefact.objects.create(- team=self.team,- report=report,- type=SignalReportArtefact.ArtefactType.ACTIONABILITY_JUDGMENT,- content=content,- )- SignalReportArtefact.objects.filter(id=artefact.id).update(created_at=created_at)-- def test_migration_fills_reports_judged_before_the_columns_existed(self):- judged = self._report(actionability=None)- self._judgment(- judged,- content=json.dumps({"actionability": "not_actionable", "already_addressed": False}),- created_at=datetime(2026, 1, 1, tzinfo=UTC),- )- self._judgment(- judged,- content=json.dumps({"actionability": "immediately_actionable", "already_addressed": True}),- created_at=datetime(2026, 1, 2, tzinfo=UTC),- )- self._judgment(judged, content="not json", created_at=datetime(2026, 1, 3, tzinfo=UTC))- other = self._report(actionability=None)- self._judgment(- other,- content=json.dumps({"actionability": "requires_human_input", "already_addressed": False}),- created_at=datetime(2026, 1, 2, tzinfo=UTC),- )- unjudged = self._report(actionability=None)- # The receivers keep the columns current today, so clearing them is what a report judged- # before those columns existed looks like.- SignalReport.objects.all().update(latest_actionability=None, latest_already_addressed=None)-- migration = importlib.import_module("products.signals.backend.migrations.0154_backfill_report_actionability")- migration.backfill_report_actionability(apps, None)-- assert self._cached(judged) == ("immediately_actionable", True)- assert self._cached(other) == ("requires_human_input", False)- assert self._cached(unjudged) == (None, None)-- def test_migration_keeps_a_judgment_stored_after_its_artefact_read(self):- report = self._report(actionability=None)- self._judgment(- report,- content=json.dumps({"actionability": "not_actionable", "already_addressed": False}),- created_at=datetime(2026, 1, 1, tzinfo=UTC),- )- SignalReport.objects.all().update(latest_actionability=None, latest_already_addressed=None)- migration = importlib.import_module("products.signals.backend.migrations.0154_backfill_report_actionability")- latest_judgment = migration._latest_judgment-- def judged_again_before_the_update(*args, **kwargs):- SignalReportArtefact.objects.create(- team=self.team,- report=report,- type=SignalReportArtefact.ArtefactType.ACTIONABILITY_JUDGMENT,- content=json.dumps({"actionability": "immediately_actionable", "already_addressed": True}),- )- return latest_judgment(*args, **kwargs)-- with patch.object(migration, "_latest_judgment", side_effect=judged_again_before_the_update):- migration.backfill_report_actionability(apps, None)-- assert self._cached(report) == ("immediately_actionable", True)