Skip to content

Commit cda34b5

Browse files
authored
fix(ingest/looker): update for Looker query API breaking change (#9865)
1 parent ae1806f commit cda34b5

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

metadata-ingestion/src/datahub/ingestion/source/looker/looker_lib_wrapper.py

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Look,
1818
LookmlModel,
1919
LookmlModelExplore,
20+
LookWithQuery,
2021
Query,
2122
User,
2223
WriteQuery,
@@ -64,6 +65,7 @@ class LookerAPIStats(BaseModel):
6465
all_looks_calls: int = 0
6566
all_models_calls: int = 0
6667
get_query_calls: int = 0
68+
get_look_calls: int = 0
6769
search_looks_calls: int = 0
6870
search_dashboards_calls: int = 0
6971

@@ -255,6 +257,14 @@ def get_query(self, query_id: str, fields: Union[str, List[str]]) -> Query:
255257
transport_options=self.transport_options,
256258
)
257259

260+
def get_look(self, look_id: str, fields: Union[str, List[str]]) -> LookWithQuery:
261+
self.client_stats.get_look_calls += 1
262+
return self.client.look(
263+
look_id=look_id,
264+
fields=self.__fields_mapper(fields),
265+
transport_options=self.transport_options,
266+
)
267+
258268
def search_dashboards(
259269
self, fields: Union[str, List[str]], deleted: str
260270
) -> Sequence[Dashboard]:

metadata-ingestion/src/datahub/ingestion/source/looker/looker_source.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,18 @@ def extract_independent_looks(self) -> Iterable[MetadataWorkUnit]:
11991199
logger.info(f"query_id is None for look {look.title}({look.id})")
12001200
continue
12011201

1202-
query: Query = self.looker_api.get_query(look.query_id, query_fields)
1202+
if look.id is not None:
1203+
query: Optional[Query] = self.looker_api.get_look(
1204+
look.id, fields=["query"]
1205+
).query
1206+
# Only include fields that are in the query_fields list
1207+
query = Query(
1208+
**{
1209+
key: getattr(query, key)
1210+
for key in query_fields
1211+
if hasattr(query, key)
1212+
}
1213+
)
12031214

12041215
dashboard_element: Optional[
12051216
LookerDashboardElement

metadata-ingestion/tests/integration/looker/test_looker.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,17 @@ def setup_mock_look(mocked_client):
311311
)
312312
]
313313

314-
mocked_client.query.return_value = Query(
315-
id="1",
316-
view="sales_explore",
317-
model="sales_model",
318-
fields=[
319-
"sales.profit",
320-
],
321-
dynamic_fields=None,
322-
filters=None,
314+
mocked_client.look.return_value = LookWithQuery(
315+
query=Query(
316+
id="1",
317+
view="sales_explore",
318+
model="sales_model",
319+
fields=[
320+
"sales.profit",
321+
],
322+
dynamic_fields=None,
323+
filters=None,
324+
)
323325
)
324326

325327

0 commit comments

Comments
 (0)