@@ -1403,21 +1403,24 @@ def create(
1403
1403
) -> DeployabilityIndex :
1404
1404
if not isinstance (snapshots , dict ):
1405
1405
snapshots = {s .snapshot_id : s for s in snapshots }
1406
- dag = snapshots_to_dag (snapshots .values ())
1407
- reversed_dag = dag .reversed .graph
1408
1406
1409
1407
deployability_mapping : t .Dict [SnapshotId , bool ] = {}
1408
+ children_deployability_mapping : t .Dict [SnapshotId , bool ] = {}
1410
1409
representative_shared_version_ids : t .Set [SnapshotId ] = set ()
1411
1410
1412
1411
start_date_cache : t .Optional [t .Dict [str , datetime ]] = {}
1413
1412
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 :
1421
1424
snapshot = snapshots [node ]
1422
1425
is_forward_only_model = snapshot .is_model and snapshot .model .forward_only
1423
1426
has_auto_restatement = (
@@ -1446,8 +1449,8 @@ def _visit(node: SnapshotId, deployable: bool = True) -> None:
1446
1449
if not snapshot .is_paused or snapshot .is_indirect_non_breaking :
1447
1450
# This snapshot represents what's currently deployed in prod.
1448
1451
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
1451
1454
children_deployable = (
1452
1455
is_valid_start
1453
1456
and not (
@@ -1456,18 +1459,12 @@ def _visit(node: SnapshotId, deployable: bool = True) -> None:
1456
1459
and not has_auto_restatement
1457
1460
)
1458
1461
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 :
1461
1464
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 )
1468
1465
1469
- for node in dag . roots :
1470
- _visit ( node )
1466
+ deployability_mapping [ node ] = this_deployable
1467
+ children_deployability_mapping [ node ] = children_deployable
1471
1468
1472
1469
deployable_ids = {
1473
1470
snapshot_id for snapshot_id , deployable in deployability_mapping .items () if deployable
0 commit comments