Repository navigation
fix(plan): resolve physical parent tables in AuditOnlyRunStage #6261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -92,9 +92,13 @@ class AuditOnlyRunStage: | |||||||||||||
|
|
||||||||||||||
| Args: | ||||||||||||||
| snapshots: Snapshots to run audits for. | ||||||||||||||
| all_snapshots: All snapshots in the plan by name. | ||||||||||||||
| deployability_index: Deployability index for this stage. | ||||||||||||||
| """ | ||||||||||||||
|
|
||||||||||||||
| snapshots: t.List[Snapshot] | ||||||||||||||
| all_snapshots: t.Dict[str, Snapshot] | ||||||||||||||
| deployability_index: DeployabilityIndex | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| @dataclass | ||||||||||||||
|
|
@@ -344,10 +348,6 @@ def build(self, plan: EvaluatablePlan) -> t.List[PlanStage]: | |||||||||||||
| ) | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| audit_only_snapshots = self._get_audit_only_snapshots(new_snapshots) | ||||||||||||||
| if audit_only_snapshots: | ||||||||||||||
| stages.append(AuditOnlyRunStage(snapshots=list(audit_only_snapshots.values()))) | ||||||||||||||
|
|
||||||||||||||
| if missing_intervals_before_promote: | ||||||||||||||
| stages.append( | ||||||||||||||
| BackfillStage( | ||||||||||||||
|
|
@@ -372,6 +372,35 @@ def build(self, plan: EvaluatablePlan) -> t.List[PlanStage]: | |||||||||||||
| ) | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| audit_only_snapshots = self._get_audit_only_snapshots( | ||||||||||||||
| plan, new_snapshots, deployability_index, needs_backfill | ||||||||||||||
| ) | ||||||||||||||
| audit_only_before_promote: t.List[Snapshot] = [] | ||||||||||||||
| audit_only_after_promote: t.List[Snapshot] = [] | ||||||||||||||
| if audit_only_snapshots: | ||||||||||||||
| after_promote_work_ids = {s.snapshot_id for s in missing_intervals_after_promote} | { | ||||||||||||||
| s.snapshot_id | ||||||||||||||
| for s in snapshots_with_schema_migration | ||||||||||||||
| if s.requires_schema_migration_in_prod and not s.is_metadata | ||||||||||||||
| } | ||||||||||||||
| for s_id in list(after_promote_work_ids): | ||||||||||||||
| after_promote_work_ids.update(dag.downstream(s_id)) | ||||||||||||||
|
|
||||||||||||||
| audit_only_before_promote = [ | ||||||||||||||
| s for s_id, s in audit_only_snapshots.items() if s_id not in after_promote_work_ids | ||||||||||||||
| ] | ||||||||||||||
| audit_only_after_promote = [ | ||||||||||||||
| s for s_id, s in audit_only_snapshots.items() if s_id in after_promote_work_ids | ||||||||||||||
| ] | ||||||||||||||
| if audit_only_before_promote: | ||||||||||||||
| stages.append( | ||||||||||||||
| AuditOnlyRunStage( | ||||||||||||||
|
Comment on lines
+395
to
+397
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clear development intervals for production restatements before the audit can fail. The before-promote backfill rewrites restated production intervals. The audit-only stage then runs before the restatement stage. If that audit raises Place the restatement stage directly after the before-promote backfill and before the audit-only stage. The stage still runs after the backfill, so other plans do not see empty production intervals. It clears only development intervals, so the audit still reads restated production data. Suggested fix
|
||||||||||||||
| snapshots=audit_only_before_promote, | ||||||||||||||
| all_snapshots=snapshots_by_name, | ||||||||||||||
| deployability_index=deployability_index, | ||||||||||||||
| ) | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| # note: "restatement stage" (which is clearing intervals in state - not actually performing the restatements, that's the backfill stage) | ||||||||||||||
| # needs to come *after* the backfill stage so that at no time do other plans / runs see empty prod intervals and compete with this plan to try to fill them. | ||||||||||||||
| # in addition, when we update intervals in state, we only clear intervals from dev snapshots to force dev models to be backfilled based on the new prod data. | ||||||||||||||
|
|
@@ -416,6 +445,15 @@ def build(self, plan: EvaluatablePlan) -> t.List[PlanStage]: | |||||||||||||
| ) | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| if audit_only_after_promote: | ||||||||||||||
| stages.append( | ||||||||||||||
| AuditOnlyRunStage( | ||||||||||||||
| snapshots=audit_only_after_promote, | ||||||||||||||
| all_snapshots=snapshots_by_name, | ||||||||||||||
| deployability_index=deployability_index, | ||||||||||||||
| ) | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| if not plan.is_dev and plan.ensure_finalized_snapshots and promoted_snapshots: | ||||||||||||||
| # Unpause right before updating the virtual layer and finalizing the environment in case when | ||||||||||||||
| # we need to use the finalized snapshots for subsequent plan applications. | ||||||||||||||
|
|
@@ -604,8 +642,18 @@ def _missing_intervals( | |||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| def _get_audit_only_snapshots( | ||||||||||||||
| self, new_snapshots: t.Dict[SnapshotId, Snapshot] | ||||||||||||||
| self, | ||||||||||||||
| plan: EvaluatablePlan, | ||||||||||||||
| new_snapshots: t.Dict[SnapshotId, Snapshot], | ||||||||||||||
| deployability_index: DeployabilityIndex, | ||||||||||||||
| needs_backfill: bool, | ||||||||||||||
| ) -> t.Dict[SnapshotId, Snapshot]: | ||||||||||||||
| promoted_snapshot_ids = ( | ||||||||||||||
| set(plan.environment.promoted_snapshot_ids) | ||||||||||||||
| if plan.environment.promoted_snapshot_ids is not None | ||||||||||||||
| else None | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| metadata_snapshots = [] | ||||||||||||||
| for snapshot in new_snapshots.values(): | ||||||||||||||
| if ( | ||||||||||||||
|
|
@@ -616,6 +664,23 @@ def _get_audit_only_snapshots( | |||||||||||||
| ): | ||||||||||||||
| continue | ||||||||||||||
|
|
||||||||||||||
| if not ( | ||||||||||||||
| plan.is_selected_for_backfill(snapshot.name) | ||||||||||||||
| or promoted_snapshot_ids is None | ||||||||||||||
| or snapshot.snapshot_id in promoted_snapshot_ids | ||||||||||||||
| ): | ||||||||||||||
| continue | ||||||||||||||
|
|
||||||||||||||
| if ( | ||||||||||||||
| plan.is_dev | ||||||||||||||
| and needs_backfill | ||||||||||||||
| and not snapshot.is_symbolic | ||||||||||||||
| and not deployability_index.is_deployable(snapshot) | ||||||||||||||
| and not plan.is_selected_for_backfill(snapshot.name) | ||||||||||||||
| and not snapshot.dev_intervals | ||||||||||||||
|
Comment on lines
+678
to
+680
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use The guard skips a dev-plan metadata audit when the candidate is not deployable and has no Test representativeness instead of deployability. Candidates that are not representative and have no development intervals remain skipped. Suggested fix
Committable suggestion
|
||||||||||||||
| ): | ||||||||||||||
| continue | ||||||||||||||
|
|
||||||||||||||
| metadata_snapshots.append(snapshot) | ||||||||||||||
|
|
||||||||||||||
| # Bulk load all the previous snapshots | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Order audits that read tables with pending migrations or backfills after that work.
An audit can query a table through a reference that is not a model dependency. Audit references do not add edges to
Snapshot.parents. A model that only auditsdb.incis therefore not a DAG descendant ofdb.inc. Its audit can be placed in the early audit stage atstages.py:395-402, which runs beforeMigrateSchemasStageatstages.py:419-426. If that audit reads a column that the forward-only migration adds todb.inc, the audit runs against a table without that column. A blocking audit then fails and can stop the plan before the migration runs.The required behavior is that an audit runs only after every pending schema migration and after-promote backfill of the tables it reads. The placement logic must account for audit table references, not only model
depends_onedges. Choose the mechanism in the implementation.