@@ -488,31 +488,39 @@ def resolve(self) -> None:
488488 def __resolve_count_descendants (self ) -> None :
489489 empty_set : Set [str ] = set ()
490490
491- def count_descendants_of (identifier : str , ancestor_kind : str , path : List [str ]) -> Dict [str , int ]:
491+ def count_descendants_of (rid : str , rname : str , ancestor_kind : str , path : List [str ]) -> Dict [str , int ]:
492492 result : DefaultDict [str , int ] = defaultdict (int )
493- ancestor_path = ["ancestors" , ancestor_kind , "reported" , "id" ]
493+ rid_path = ["ancestors" , ancestor_kind , "reported" , "id" ]
494+ rname_path = ["ancestors" , ancestor_kind , "reported" , "name" ]
494495 for _ , elem in self .g .nodes (data = True ):
495- if value_in_path (elem , ancestor_path ) == identifier :
496+ if value_in_path (elem , rid_path ) == rid and value_in_path ( elem , rname_path ) == rname :
496497 kinds_set = elem .get ("kinds_set" , empty_set )
497498 extracted = value_in_path (elem , path )
498499 if "phantom_resource" not in kinds_set and isinstance (extracted , str ):
499500 result [extracted ] += 1
500501 return result
501502
502- for on_kind , prop in GraphResolver .count_successors .items ():
503- for _ , node in self .g .nodes (data = True ):
504- kinds = node .get ("kinds_set" )
505- if kinds and on_kind in kinds :
506- if rid := value_in_path (node , NodePath .reported_id ):
507- # descendant summary
508- summary = count_descendants_of (rid , on_kind , prop .extract_path )
503+ empty_set = set ()
504+ for _ , node in self .g .nodes (data = True ):
505+ kinds = node .get ("kinds_set" , empty_set )
506+ for on_kind , prop in GraphResolver .count_successors .items ():
507+ if on_kind in kinds :
508+ if (rid := value_in_path (node , NodePath .reported_id )) and (
509+ rname := value_in_path (node , NodePath .reported_name )
510+ ):
511+ # Descendant summary: we need to compare id and name.
512+ # Example AWS global region: id=us-east-1, name=global
513+ summary = count_descendants_of (rid , rname , on_kind , prop .extract_path )
509514 set_value_in_path (summary , prop .to_path , node )
510515 # descendant count
511516 total = reduce (lambda left , right : left + right , summary .values (), 0 )
512517 set_value_in_path (total , NodePath .descendant_count , node )
513518 # update hash
514519 node ["hash" ] = GraphBuilder .content_hash (
515- node ["reported" ], node .get ("desired" ), node .get ("metadata" ), node .get ("kinds" )
520+ node ["reported" ],
521+ desired = node .get ("desired" ),
522+ metadata = node .get ("metadata" ),
523+ kinds = node .get ("kinds" ),
516524 )
517525
518526 def __resolve (self , node_id : NodeId , node : Json ) -> Json :
0 commit comments