Skip to content

Commit c1242e1

Browse files
committed
fix: fix loading aggregated facts for entity dataset
JIRA: CQ-1236 risk: low
1 parent fac5ac1 commit c1242e1

File tree

6 files changed

+1574
-1582
lines changed

6 files changed

+1574
-1582
lines changed

gooddata-sdk/gooddata_sdk/catalog/entity.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from gooddata_sdk.catalog.base import Base, JsonApiEntityBase
1313
from gooddata_sdk.compute.model.base import ObjId
14-
from gooddata_sdk.utils import AllPagedEntities
14+
from gooddata_sdk.utils import AllPagedEntities, safeget_list
1515

1616
T = TypeVar("T", bound="AttrCatalogEntity")
1717

@@ -84,6 +84,10 @@ def from_api(
8484
def client_class() -> Any:
8585
return NotImplemented
8686

87+
def _relation_entity_from_side_loads(self, entity: builtins.type[T], path: list[str]) -> list[T]:
88+
related_fact_ids = [(x.get("id"), x.get("type")) for x in safeget_list(self.json_api_relationships, path)]
89+
return [entity.from_api(sl) for sl in self.json_api_side_loads if (sl["id"], sl["type"]) in related_fact_ids]
90+
8791

8892
class CatalogEntity:
8993
def __init__(self, entity: dict[str, Any]) -> None:

gooddata-sdk/gooddata_sdk/catalog/workspace/content_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def get_full_catalog(self, workspace_id: str, inject_valid_objects_func: bool =
7979
get_datasets = functools.partial(
8080
self._entities_api.get_all_entities_datasets,
8181
workspace_id,
82-
include=["attributes", "facts"],
82+
include=["attributes", "facts", "aggregatedFacts"],
8383
_check_return_type=False,
8484
)
8585

gooddata-sdk/gooddata_sdk/catalog/workspace/entity_model/content_objects/dataset.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)