@@ -106,9 +106,7 @@ class CatalogAggregatedFact(AttrCatalogEntity):
106106 def client_class () -> Any :
107107 return JsonApiAggregatedFactOut
108108
109- def as_computable (self ) -> Metric :
110- return SimpleMetric (local_id = self .id , item = self .obj_id )
111-
109+ # as_computable skipped because aggregated fact cannot be ever used in metric
112110 # TODO - dataset?
113111
114112
@@ -131,28 +129,22 @@ def generate_attributes_from_api(self) -> list[CatalogAttribute]:
131129 repr = False ,
132130 default = attr .Factory (lambda self : self .generate_attributes_from_api (), takes_self = True ),
133131 )
134-
135- def generate_facts_from_api (self ) -> list [CatalogFact ]:
136- related_fact_ids = [x .get ("id" ) for x in safeget_list (self .json_api_relationships , ["facts" , "data" ])]
137- return [
138- CatalogFact .from_api (sl )
139- for sl in self .json_api_side_loads
140- if sl ["type" ] == "fact" and sl ["id" ] in related_fact_ids
141- ]
142-
143132 facts : list [CatalogFact ] = attr .field (
144133 repr = False ,
145- default = attr .Factory (lambda self : self .generate_facts_from_api (), takes_self = True ),
134+ default = attr .Factory (
135+ lambda self : self ._relation_entity_from_side_loads (CatalogFact , ["facts" , "data" ]), takes_self = True
136+ ),
146137 )
147-
148- # TODO: Doublecheck if we shouldn't do something like for facts
149138 aggregated_facts : Optional [list [CatalogAggregatedFact ]] = attr .field (
150- default = attr .Factory (lambda self : self .json_api_attributes .get ("aggregatedFacts" ), takes_self = True ),
139+ repr = False ,
140+ default = attr .Factory (
141+ lambda self : self ._relation_entity_from_side_loads (CatalogAggregatedFact , ["aggregatedFacts" , "data" ]),
142+ takes_self = True ,
143+ ),
151144 )
152145 precedence : Optional [int ] = attr .field (
153146 default = attr .Factory (lambda self : self .json_api_attributes .get ("precedence" ), takes_self = True )
154147 )
155-
156148 grain : Optional [list ] = attr .field (
157149 default = attr .Factory (lambda self : self .json_api_attributes .get ("grain" ), takes_self = True )
158150 )
0 commit comments