chore(devex): move alert and action models to product folders#59224
Conversation
Move 7 Django models out of posthog/models/ into their respective product backends as part of the ongoing product isolation effort. alerts (5 models): Alert, Threshold, AlertConfiguration, AlertSubscription, AlertCheck → products/alerts/backend/models/ actions (2 models): Action, ActionStep + util → products/actions/backend/models/ State-only migrations with SeparateDatabaseAndState — no DB changes, tables keep their posthog_ prefix via explicit db_table. ContentType rows updated via RunPython. Cross-app FKs (PluginConfig.match_action, TaggedItem.action, Survey.actions) re-pointed to the new app labels. Both teams confirmed these assignments (analytics platform, March 2026).
|
🎭 Playwright didn't run on this PR — your changes touch code that could affect E2E behavior, but Playwright is opt-in via label now to keep CI cost down. Add the Most PRs don't need this. Real regressions still get caught on master and fix-forward. |
Migration SQL ChangesHey 👋, we've detected some migrations on this PR. Here's the SQL output for each migration, make sure they make sense:
|
🔍 Migration Risk AnalysisWe've analyzed your migrations for potential risks. Summary: 3 Safe | 1 Needs Review | 0 Blocked
|
Move API viewsets, serializers, and tests alongside their models: - posthog/api/alert.py, alert_schedule_restriction.py → products/alerts/backend/api/ - posthog/api/action.py → products/actions/backend/api/ - test files to respective test dirs Fix relative imports that broke on move, update router import in posthog/api/__init__.py, update cross-product references (surveys, insight). Add ANN exemption for the moved files (pre-existing violations, same pattern as all other products).
…ctions-to-product # Conflicts: # posthog/migrations/max_migration.txt
…ctions-to-product # Conflicts: # posthog/migrations/max_migration.txt # posthog/tasks/alerts/checks.py # posthog/tasks/alerts/test/test_alert_checks.py # posthog/tasks/alerts/utils.py
posthog/1168 deletes Action from posthog state, but surveys/0001_initial has to="posthog.action" on the M2M field. Without an explicit dependency on surveys/0002 (which repoints to="actions.action"), Django's system check fails with a lazy reference error because the deletion runs before the repoint.
- Add surveys/0002 dependency to posthog/1168 so the M2M repoint runs before the DeleteModel (fixes lazy reference validation error) - Fix alert imports in new test files from #53837 merge - Fix Action.__str__ return type (name is nullable)
Another new file from #53837 merge that still imported AlertCheck from posthog.models.alert instead of products.alerts.backend.models.
…ctions-to-product
- Add products.actions module to tach.toml and wire depends_on for ee, posthog, dashboards, surveys, web_analytics, product_analytics, marketing_analytics, experiments - Fix mock patch string in test_property.py (posthog.models.Action → products.actions.backend.models.action.Action) - Update alerts 0001 migration to reflect final model state: remove is_calculating field (dropped in 1167), add EVERY_15_MINUTES choice and max_length=20 for calculation_interval (altered in 1164)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 35e9518a53
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR relocates the Django alerts and actions models out of posthog/models/ into their respective products/*/backend/models/ packages to reduce cross-team migration conflicts, while preserving existing database tables via SeparateDatabaseAndState and repointing cross-app FK/M2M references plus ContentType rows.
Changes:
- Moved Alerts (5 models) and Actions (2 models + util) into new product backend apps, adding app configs, model
db_tablemappings, and state-only migrations. - Repointed cross-app relations (e.g.
PluginConfig.match_action,TaggedItem.action,Survey.actions) and added aRunPythonmigration to migrate ContentType/Permission references. - Mechanically rewired imports across the codebase and updated module dependency rules (tach) and products ruff configuration.
Reviewed changes
Copilot reviewed 213 out of 223 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tach.toml | Adds module dependency declarations for new products.actions / products.alerts modules. |
| products/ruff.toml | Adds temporary annotation-rule exemptions for new actions/alerts backends. |
| posthog/settings/web.py | Registers the new Django apps for actions and alerts. |
| posthog/migrations/max_migration.txt | Advances PostHog max migration pointer for the move. |
| posthog/migrations/1168_migrate_alerts_actions_models.py | State-only model removals + ContentType migration for actions/alerts + FK repointing. |
| products/actions/backend/apps.py | Introduces actions Django app config/label. |
| products/actions/backend/models/action.py | Moves Action model into product module, adds db_table, updates FKs to posthog.*. |
| products/actions/backend/models/action_step.py | Moves ActionStep model and pins db_table. |
| products/actions/backend/models/util.py | Moves action util helpers and updates imports/typing. |
| products/actions/backend/models/init.py | Exposes new actions models as a package API. |
| products/actions/backend/migrations/max_migration.txt | Sets actions app max migration pointer. |
| products/actions/backend/migrations/0001_migrate_actions_models.py | State-only create models for actions app (no DB ops). |
| products/actions/backend/api/action.py | Moves Action API/viewset & serializers under products, rewires imports. |
| products/actions/backend/api/test/test_action.py | Updates tests to import Action from new location. |
| products/alerts/backend/apps.py | Introduces alerts Django app config/label. |
| products/alerts/backend/models/alert.py | Moves alert-related models into product module, adds db_table, updates FKs and typing. |
| products/alerts/backend/models/init.py | Exposes new alerts models as a package API. |
| products/alerts/backend/migrations/max_migration.txt | Sets alerts app max migration pointer. |
| products/alerts/backend/migrations/0001_migrate_models.py | State-only create models for alerts app (no DB ops). |
| products/alerts/backend/api/alert.py | Moves alert API under products and updates model/type imports and signal handlers typing. |
| products/alerts/backend/api/alert_schedule_restriction.py | Adds Pydantic OpenAPI types for schedule restriction payloads under alerts product. |
| products/alerts/backend/api/test/test_alert.py | Updates tests to import alert models from new location and patch new API path. |
| products/alerts/backend/max_tools.py | Updates Max tools to import alerts models from new module. |
| products/alerts/backend/test_max_tools.py | Updates Max tools tests to import alerts models from new module. |
| products/surveys/backend/models.py | Repoints Survey.actions M2M to new Action import. |
| products/surveys/backend/migrations/max_migration.txt | Advances surveys max migration pointer. |
| products/surveys/backend/migrations/0002_action_fk_repoint.py | State-only M2M repoint to actions.Action. |
| products/surveys/backend/api/survey.py | Repoints serializers and Action imports to products/actions modules. |
| products/surveys/backend/api/test/test_survey.py | Updates tests to import Action from new location. |
| products/web_analytics/backend/test/test_weekly_digest.py | Updates tests to import Action from new location. |
| products/product_analytics/backend/hogql_queries/stickiness/stickiness_query_runner.py | Updates Action import path. |
| products/product_analytics/backend/hogql_queries/stickiness/test/test_stickiness_query_runner.py | Updates test Action import path. |
| products/marketing_analytics/backend/hogql_queries/conversion_goal_processor.py | Updates Action import path. |
| products/marketing_analytics/backend/hogql_queries/test_conversion_goal_processor.py | Updates tests to import Action from new location. |
| products/marketing_analytics/backend/hogql_queries/test_conversion_goals_aggregator.py | Updates tests to import Action from new location. |
| products/marketing_analytics/backend/hogql_queries/test_marketing_analytics_table_query_runner_compare.py | Updates tests to import Action from new location. |
| products/marketing_analytics/backend/hogql_queries/test_marketing_analytics_table_query_runner_business.py | Updates tests to import Action from new location. |
| products/dashboards/backend/api/dashboard.py | Updates imports to use AlertConfiguration from new alerts module. |
| products/dashboards/backend/api/dashboard.py:970:9 | Adds a (likely accidental) static type-checker diagnostic artifact file. |
| posthog/api/init.py | Routes Action endpoints to the new products.actions viewset; wires alerts API import. |
| posthog/api/insight.py | Updates AlertConfiguration and AlertSerializer imports to the new alerts module. |
| posthog/api/file_system/registrations.py | Repoints file-system registration app label for Action to actions. |
| posthog/admin/admins/alert_admin.py | Repoints admin import to products.alerts model. |
| posthog/models/init.py | Removes Action / ActionStep / AlertConfiguration exports from posthog.models. |
| posthog/models/action/init.py | Removes old action package re-export. |
| posthog/models/plugin.py | Repoints PluginConfig.match_action FK to actions.Action. |
| posthog/models/tagged_item.py | Repoints TaggedItem.action FK to actions.Action. |
| posthog/models/organization.py | Repoints alert subscription cleanup import to new alerts module. |
| posthog/middleware.py | Updates Action import path. |
| posthog/test/base.py | Updates Action import path for core test base. |
| posthog/test/test_middleware.py | Updates Action import path. |
| posthog/models/test/test_event_model.py | Updates Action import path. |
| posthog/models/test/test_hog_function.py | Updates Action import path. |
| posthog/models/test/test_hog_flow.py | Updates Action import path. |
| posthog/models/test/test_remote_config.py | Updates Action import path. |
| posthog/models/test/test_tagged_item_model.py | Updates Action import path. |
| posthog/models/property/util.py | Updates Action + action util imports to new actions module. |
| posthog/models/entity/entity.py | Updates Action import path. |
| posthog/models/entity/util.py | Updates action util imports to new actions module. |
| posthog/models/cohort/util.py | Updates Action + action util imports to new actions module. |
| posthog/models/event/query_event_list.py | Updates Action + action util imports to new actions module. |
| posthog/models/file_system/unfiled_file_saver.py | Updates Action import path. |
| posthog/models/hog_flow/hog_flow.py | Updates Action import path. |
| posthog/models/hog_functions/hog_function.py | Updates Action import path. |
| posthog/models/resource_transfer/visitors/action.py | Updates visitor model import to new actions module. |
| posthog/models/resource_transfer/visitors/cohort.py | Updates dynamic edge import to new actions module. |
| posthog/models/resource_transfer/visitors/experiment.py | Updates dynamic edge import to new actions module. |
| posthog/models/resource_transfer/visitors/experiment_saved_metric.py | Updates dynamic edge import to new actions module. |
| posthog/models/resource_transfer/visitors/feature_flag.py | Updates Action import path. |
| posthog/models/resource_transfer/visitors/insight.py | Updates dynamic edge import to new actions module. |
| posthog/models/resource_transfer/test/test_inter_project_transferer.py | Updates tests to import Action from new location. |
| posthog/models/resource_transfer/test/test_visitors.py | Updates tests to import Action from new location. |
| posthog/tasks/hog_flows.py | Updates Action import path. |
| posthog/tasks/hog_functions.py | Updates Action import path. |
| posthog/tasks/exports/test/test_csv_exporter.py | Updates tests to import Action from new location. |
| posthog/queries/trends/trends.py | Updates Action import path. |
| posthog/queries/trends/breakdown.py | Updates action util import path. |
| posthog/queries/funnels/base.py | Updates action util import path. |
| posthog/queries/funnels/test/test_funnel.py | Updates tests to import Action from new location. |
| posthog/queries/test/test_lifecycle.py | Updates tests to import Action from new location. |
| posthog/queries/test/test_trends.py | Updates tests to import Action from new location. |
| posthog/queries/foss_cohort_query.py | Updates Action import path. |
| posthog/queries/column_optimizer/foss_column_optimizer.py | Updates action util import path. |
| posthog/tasks/alerts/utils.py | Updates alerts model imports to new alerts module. |
| posthog/tasks/alerts/trends.py | Updates AlertConfiguration import path. |
| posthog/tasks/alerts/detector.py | Updates AlertConfiguration import path. |
| posthog/tasks/alerts/schedule_restriction.py | Updates AlertConfiguration import path. |
| posthog/tasks/alerts/investigation_notifications.py | Updates alerts model imports to new alerts module. |
| posthog/tasks/alerts/test/alert_check_helpers.py | Updates AlertConfiguration import path. |
| posthog/tasks/alerts/test/test_alert_check_helpers.py | Updates AlertCheck import path. |
| posthog/tasks/alerts/test/test_alert_evaluation.py | Updates alerts model imports to new alerts module. |
| posthog/tasks/alerts/test/test_alert_subscriptions.py | Updates alerts model imports to new alerts module. |
| posthog/tasks/alerts/test/test_detector_breakdowns.py | Updates AlertConfiguration import path. |
| posthog/tasks/alerts/test/test_investigation_notifications.py | Updates alerts model imports to new alerts module. |
| posthog/tasks/alerts/test/test_schedule_restriction.py | Updates AlertConfiguration import path. |
| posthog/tasks/alerts/test/test_trends_absolute_alerts.py | Updates alerts model imports to new alerts module. |
| posthog/tasks/alerts/test/test_trends_relative_alerts.py | Updates alerts model imports to new alerts module. |
| posthog/test/activity_logging/test_alert_activity_logging.py | Updates alert subscription imports to new alerts module. |
| posthog/temporal/alerts/activities.py | Updates alerts model imports to new alerts module. |
| posthog/temporal/alerts/investigation.py | Updates alerts model imports to new alerts module. |
| posthog/temporal/ai/sync_vectors.py | Updates Action import path. |
| posthog/temporal/ai/anomaly_investigation/notebook.py | Updates alerts model imports to new alerts module. |
| posthog/temporal/ai/anomaly_investigation/runner.py | Updates AlertConfiguration import path. |
| posthog/temporal/ai/anomaly_investigation/tools.py | Updates AlertConfiguration import path. |
| posthog/temporal/ai/anomaly_investigation/workflow.py | Updates alerts model imports to new alerts module. |
| posthog/temporal/tests/ai/test_anomaly_investigation_notebook.py | Updates alerts model imports to new alerts module. |
| posthog/temporal/tests/ai/test_anomaly_investigation_verdict.py | Updates alerts model imports to new alerts module. |
| posthog/temporal/tests/ai/test_sync_vectors.py | Updates Action import path. |
| posthog/temporal/tests/test_alerts_activities.py | Updates alerts model imports to new alerts module. |
| posthog/temporal/tests/test_alerts_investigation.py | Updates alerts model imports to new alerts module. |
| posthog/temporal/tests/test_alerts_workflows.py | Updates alerts model imports to new alerts module. |
| posthog/session_recordings/queries/utils.py | Updates Action import path. |
| posthog/session_recordings/queries/test/listing_recordings/test_session_recording_list_by_top_level_event_property.py | Updates tests to import Action from new location. |
| posthog/session_recordings/queries/test/listing_recordings/test_session_recording_list_from_query.py | Updates tests to import Action from new location. |
| posthog/hogql/property.py | Updates Action/ActionStepJSON imports to new actions module. |
| posthog/hogql/functions/action.py | Updates Action import path. |
| posthog/hogql/functions/test/test_action.py | Updates tests to import Action from new location. |
| posthog/hogql/test/test_action_to_expr.py | Updates tests to import Action/ActionStepJSON from new location. |
| posthog/hogql/test/test_property.py | Updates patch target for Action.objects.get to new import path. |
| posthog/hogql/database/schema/test/test_system_tables.py | Updates Action and AlertConfiguration imports to new locations. |
| posthog/hogql_queries/query_metadata.py | Updates Action import path. |
| posthog/hogql_queries/sessions_query_runner.py | Updates Action import path. |
| posthog/hogql_queries/events_query_runner.py | Updates Action/ActionStepJSON imports to new actions module. |
| posthog/hogql_queries/utils/timestamp_utils.py | Updates Action import path. |
| posthog/hogql_queries/utils/test/test_timestamp_utils.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/test/test_query_metadata.py | Updates tests to import/patch Action from new location. |
| posthog/hogql_queries/ai/event_taxonomy_query_runner.py | Updates Action import path. |
| posthog/hogql_queries/ai/test/test_event_taxonomy_query_runner.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/web_analytics/web_goals.py | Updates Action import path. |
| posthog/hogql_queries/web_analytics/web_analytics_query_runner.py | Updates Action import path. |
| posthog/hogql_queries/web_analytics/test/test_web_analytics_cohort_filter.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/web_analytics/test/test_web_goals.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/web_analytics/test/test_web_overview.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/web_analytics/test/test_web_stats_table.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/web_analytics/test/test_web_stats_table_pre_aggregated_conversions.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/insights/trends/utils.py | Updates dynamic import of Action to new path. |
| posthog/hogql_queries/insights/trends/trends_query_builder.py | Updates Action import path. |
| posthog/hogql_queries/insights/trends/trends_query_runner.py | Updates Action import path. |
| posthog/hogql_queries/insights/trends/trends_actors_query_builder.py | Updates Action import path. |
| posthog/hogql_queries/insights/trends/test/test_trends.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/insights/trends/test/test_trends_persons.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/insights/trends/test/test_trends_query_runner.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/insights/trends/test/test_calendar_heatmap_query_runner.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/insights/trends/calendar_heatmap_query_runner.py | Updates Action import path. |
| posthog/hogql_queries/insights/retention/retention_query_runner.py | Updates Action import path. |
| posthog/hogql_queries/insights/retention/test/test_retention_query_runner.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/insights/lifecycle/lifecycle_query_runner.py | Updates Action import path. |
| posthog/hogql_queries/insights/lifecycle/test/test_lifecycle_query_runner.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/insights/funnels/base.py | Updates Action import path. |
| posthog/hogql_queries/insights/funnels/funnel_event_query.py | Updates Action import path. |
| posthog/hogql_queries/insights/funnels/funnel_correlation_query_runner.py | Updates Action import path. |
| posthog/hogql_queries/insights/funnels/test/test_funnel.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/insights/funnels/test/test_funnel_event_query.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/experiments/base_query_utils.py | Updates Action import path. |
| posthog/hogql_queries/experiments/exposure_query_logic.py | Updates Action import path. |
| posthog/hogql_queries/experiments/test/test_experiment_trends_query_runner.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/experiments/test/experiment_query_runner/test_base.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/experiments/test/experiment_query_runner/test_experiment_exposures_query_runner.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/experiments/test/experiment_query_runner/test_funnel_metric.py | Updates tests to import Action from new location. |
| posthog/hogql_queries/experiments/test/experiment_query_runner/test_ratio_metric.py | Updates tests to import Action from new location. |
| posthog/management/commands/test/test_migrate_hooks.py | Updates Action import path for migrate hooks tests. |
| posthog/migrations/0410_action_steps_population.py | Updates data migration’s Action import (migration logic touched). |
| posthog/demo/products/hedgebox/matrix.py | Updates demo data generator Action import path. |
| posthog/demo/legacy/app_data_generator.py | Updates demo generator Action import path. |
| posthog/demo/legacy/revenue_data_generator.py | Updates demo generator Action import path. |
| posthog/demo/legacy/web_data_generator.py | Updates demo generator Action import path. |
| posthog/cdp/filters.py | Updates Action import path. |
| posthog/cdp/test/test_filters.py | Updates tests to import Action from new location. |
| posthog/cdp/test/test_site_functions.py | Updates tests to import Action from new location. |
| posthog/api/search.py | Updates Action import path. |
| posthog/api/test/test_cohort.py | Updates tests to import Action from new location. |
| posthog/api/test/test_event.py | Updates tests to import Action from new location. |
| posthog/api/test/test_event_definition.py | Updates tests to import Action from new location. |
| posthog/api/test/test_file_system.py | Updates tests to import Action from new location. |
| posthog/api/test/test_hog_function.py | Updates tests to import Action from new location. |
| posthog/api/test/test_resource_transfer.py | Updates tests to import Action from new location. |
| .semgrep/rules/idor-team-scoped-models.py | Updates semgrep rule imports to new Action location. |
| ee/api/test/test_action.py | Updates tests to import Action from new location. |
| ee/api/test/test_hooks.py | Updates tests to import Action from new location. |
| ee/api/rbac/test/test_access_control.py | Updates runtime imports to new Action location. |
| ee/benchmarks/benchmarks.py | Updates benchmark imports to new Action location. |
| ee/clickhouse/models/test/test_action.py | Updates tests to import Action and action util functions from new location. |
| ee/clickhouse/models/test/test_cohort.py | Updates tests to import Action from new location. |
| ee/clickhouse/queries/column_optimizer.py | Updates action util import path. |
| ee/clickhouse/queries/experiments/test_utils.py | Updates tests to import Action from new location. |
| ee/clickhouse/queries/funnels/test/test_funnel.py | Updates tests to import Action from new location. |
| ee/clickhouse/queries/test/test_cohort_query.py | Updates tests to import Action from new location. |
| ee/clickhouse/queries/test/test_column_optimizer.py | Updates tests to import Action from new location. |
| ee/clickhouse/queries/test/test_event_query.py | Updates tests to import Action from new location. |
| ee/clickhouse/queries/test/test_util.py | Updates tests to import Action from new location. |
| ee/clickhouse/views/test/test_experiments_action_names.py | Updates tests to import Action from new location. |
| ee/clickhouse/views/test/test_experiment_saved_metrics.py | Updates tests’ local imports to new Action location. |
| ee/hogai/core/mixins.py | Updates Action import path. |
| ee/hogai/summarizers/actions.py | Updates Action/types import path. |
| ee/hogai/summarizers/chains.py | Updates Action import path. |
| ee/hogai/summarizers/test/test_actions.py | Updates tests to import Action from new location. |
| ee/hogai/test/test_insights_assistant.py | Updates tests to import Action from new location. |
| ee/hogai/eval/ci/eval_ui_context.py | Updates Action import path. |
| ee/hogai/context/entity_search/context.py | Updates Action and AlertConfiguration imports to new locations. |
| ee/hogai/context/entity_search/test/test_context.py | Updates tests to import Action from new location. |
| ee/hogai/chat_agent/test/test_chat_agent.py | Updates tests to import Action from new location. |
| ee/hogai/chat_agent/taxonomy/toolkit.py | Updates Action import path. |
| ee/hogai/chat_agent/taxonomy/test/test_events.py | Updates tests to import Action from new location. |
| ee/hogai/chat_agent/retention/test/test_nodes.py | Updates tests to import Action from new location. |
| ee/hogai/chat_agent/rag/nodes.py | Updates Action import path. |
| ee/hogai/chat_agent/rag/test/test_nodes.py | Updates tests to import Action from new location. |
| ee/hogai/chat_agent/query_planner/toolkit.py | Updates Action import path. |
| ee/hogai/chat_agent/query_planner/test/test_toolkit.py | Updates tests to import Action from new location. |
Comments suppressed due to low confidence (3)
products/actions/backend/api/action.py:202
ActionSerializer.get_creation_contextis annotated as returningNone, but it’s exposed as aSerializerMethodFieldwith an OpenAPICharField(allow_null=True). The return type should reflect the serializer contract (e.g.str | None) to avoid misleading typing and potential static analysis issues as this method evolves.
products/dashboards/backend/api/dashboard.py:970:9:15- This file appears to be a pasted/static type-checker diagnostic output, not source code, and it lives alongside the real
dashboard.py. It will be imported/packaged as a Python module on some tooling paths and is very likely accidental. Please delete this file and address the underlying type error inproducts/dashboards/backend/api/dashboard.pyinstead (or exclude the diagnostic from being committed).
products/actions/backend/api/action.py:44 - Directly importing
Experimenthere forces a hard dependency fromproducts.actions->products.experiments, which (given experiments already import/useAction) creates a module cycle. Consider removing this import and using a runtime lookup (e.g.django.apps.apps.get_model("experiments", "Experiment")) inside the small number of functions that need it, or moving this reference-query logic into the experiments module/facade so only one direction is needed.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| [[modules]] | ||
| path = "products.actions" | ||
| depends_on = [ | ||
| "ee", | ||
| "posthog", | ||
| "products.experiments", | ||
| ] |
| def copy_action_steps_to_json(apps, schema_editor): | ||
| from posthog.models import Action | ||
| from products.actions.backend.models.action import Action | ||
|
|
||
| all_actions_with_steps = Action.objects.prefetch_related("action_steps").order_by("pk").all() |
MCP UI Apps size report
|
|
Size Change: 0 B Total Size: 116 MB ℹ️ View Unchanged
|
ClickHouse migration SQL per cloud environmentNo ClickHouse migrations changed in this PR. |
Spurious file with colon in name from git status output.
The test patches posthog.api.action.report_user_action, but the API moved to products/actions/backend/api/action.py in #59224. The tests never ran in CI (silent skip — fixed by the lint discovery change in this same PR) so the broken patch went unnoticed.
Tightens the product lint to surface test files that no CI runner picks up, and wires up the orphans the new check found. The trigger was `products/actions/`: its `Action` model was moved into a product app in #59224, but `__init__.py` and the `backend:test` script were both missed in the move. The lint silently skipped it because `lint_all_products` discovered products via `__init__.py` presence — the exact file the lint should have been enforcing. Discovery now uses `backend/`, which is the right load-bearing signal for products that carry Python code worth linting. Frontend-only products keep getting skipped, which is fine — they have nothing for these checks to validate. New `OrphanedTestFilesCheck` walks the product directory for `test_*.py` / `*_test.py` files and verifies each is reachable from either the pytest paths in `backend:test` or a known external runner (currently `dags/` → ci-dagster.yml, plus per-product allowlists for the temporal pytest paths in ci-backend.yml). Catches: - actions: backend/api/test/test_action.py (33 tests, ~10 days stranded) - alerts: backend/api/test/test_alert.py - tasks: backend/stream/tests/test_redis_stream.py - posthog_ai: scripts/* (4 files, 50 tests) - logs: skills/authoring-log-alerts/tests/* (17 tests) Each product's `backend:test` is extended to cover its previously unreached paths. Tests in tools/hogli-commands cover the orphan check across the file-vs-directory matching, the external-runner allowlist, and the per-product exemption mapping.
The test patches posthog.api.action.report_user_action, but the API moved to products/actions/backend/api/action.py in #59224. The tests never ran in CI (silent skip — fixed by the lint discovery change in this same PR) so the broken patch went unnoticed.
Problem
Alert and action models still live in posthog/models/ causing migration conflicts for the analytics platform team. Both teams confirmed the target assignments in March 2026.
Changes
Moves 7 Django models into their product backends using SeparateDatabaseAndState (no DB changes, tables keep their
posthog_prefix):products/alerts/backend/models/products/actions/backend/models/Cross-app FK re-pointing:
PluginConfig.match_action,TaggedItem.action,Survey.actionsnow reference the new app labels. ContentType rows updated via RunPython. File system registration updated for actions.~195 files touched, almost entirely mechanical import rewrites.
How did you test this code?
manage.py migrate --planvalidates cleanrg "from posthog.models.alert\|from posthog.models.action"returns nothing)🤖 Agent context
Co-authored with Claude Code. Used the product-model-migration skill (move_scanner.py, import_rewriter.py, migrate_phased.py) for file moves, import rewrites, and FK fixes. Manual steps: apps.py creation, INSTALLED_APPS registration, SeparateDatabaseAndState migration wrapping, ContentType update functions, cross-app FK fixes (PluginConfig, TaggedItem, file_system registrations), and barrel import cleanup (second rewriter pass with
posthog.modelssymbol_remap).