@@ -1403,21 +1403,24 @@ def create(
14031403 ) -> DeployabilityIndex :
14041404 if not isinstance (snapshots , dict ):
14051405 snapshots = {s .snapshot_id : s for s in snapshots }
1406- dag = snapshots_to_dag (snapshots .values ())
1407- reversed_dag = dag .reversed .graph
14081406
14091407 deployability_mapping : t .Dict [SnapshotId , bool ] = {}
1408+ children_deployability_mapping : t .Dict [SnapshotId , bool ] = {}
14101409 representative_shared_version_ids : t .Set [SnapshotId ] = set ()
14111410
14121411 start_date_cache : t .Optional [t .Dict [str , datetime ]] = {}
14131412
1414- def _visit (node : SnapshotId , deployable : bool = True ) -> None :
1415- if deployability_mapping .get (node ) in (False , deployable ) and (
1416- deployable or node not in representative_shared_version_ids
1417- ):
1418- return
1419-
1420- if deployable and node in snapshots :
1413+ dag = snapshots_to_dag (snapshots .values ())
1414+ for node in dag :
1415+ if node not in snapshots :
1416+ continue
1417+ # Make sure that the node is deployable according to all its parents
1418+ this_deployable = all (
1419+ children_deployability_mapping [p_id ]
1420+ for p_id in snapshots [node ].parents
1421+ if p_id in children_deployability_mapping
1422+ )
1423+ if this_deployable :
14211424 snapshot = snapshots [node ]
14221425 is_forward_only_model = snapshot .is_model and snapshot .model .forward_only
14231426 has_auto_restatement = (
@@ -1446,8 +1449,8 @@ def _visit(node: SnapshotId, deployable: bool = True) -> None:
14461449 if not snapshot .is_paused or snapshot .is_indirect_non_breaking :
14471450 # This snapshot represents what's currently deployed in prod.
14481451 representative_shared_version_ids .add (node )
1449- else :
1450- this_deployable = True
1452+
1453+ # A child can still be deployable even if its parent is not
14511454 children_deployable = (
14521455 is_valid_start
14531456 and not (
@@ -1456,18 +1459,12 @@ def _visit(node: SnapshotId, deployable: bool = True) -> None:
14561459 and not has_auto_restatement
14571460 )
14581461 else :
1459- this_deployable , children_deployable = False , False
1460- if node in snapshots and not snapshots [node ].is_paused :
1462+ children_deployable = False
1463+ if not snapshots [node ].is_paused :
14611464 representative_shared_version_ids .add (node )
1462- else :
1463- representative_shared_version_ids .discard (node )
1464-
1465- deployability_mapping [node ] = deployability_mapping .get (node , True ) and this_deployable
1466- for child in reversed_dag [node ]:
1467- _visit (child , children_deployable )
14681465
1469- for node in dag . roots :
1470- _visit ( node )
1466+ deployability_mapping [ node ] = this_deployable
1467+ children_deployability_mapping [ node ] = children_deployable
14711468
14721469 deployable_ids = {
14731470 snapshot_id for snapshot_id , deployable in deployability_mapping .items () if deployable
0 commit comments