fix(ingest/looker): update for Looker query API breaking change (#9865)

This commit is contained in:
Jay Feldman 2024-02-15 19:08:01 -05:00 committed by GitHub
parent ae1806fefa
commit cda34b50fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 10 deletions

View File

@ -17,6 +17,7 @@ from looker_sdk.sdk.api40.models import (
Look,
LookmlModel,
LookmlModelExplore,
LookWithQuery,
Query,
User,
WriteQuery,
@ -64,6 +65,7 @@ class LookerAPIStats(BaseModel):
all_looks_calls: int = 0
all_models_calls: int = 0
get_query_calls: int = 0
get_look_calls: int = 0
search_looks_calls: int = 0
search_dashboards_calls: int = 0
@ -255,6 +257,14 @@ class LookerAPI:
transport_options=self.transport_options,
)
def get_look(self, look_id: str, fields: Union[str, List[str]]) -> LookWithQuery:
self.client_stats.get_look_calls += 1
return self.client.look(
look_id=look_id,
fields=self.__fields_mapper(fields),
transport_options=self.transport_options,
)
def search_dashboards(
self, fields: Union[str, List[str]], deleted: str
) -> Sequence[Dashboard]:

View File

@ -1199,7 +1199,18 @@ class LookerDashboardSource(TestableSource, StatefulIngestionSourceBase):
logger.info(f"query_id is None for look {look.title}({look.id})")
continue
query: Query = self.looker_api.get_query(look.query_id, query_fields)
if look.id is not None:
query: Optional[Query] = self.looker_api.get_look(
look.id, fields=["query"]
).query
# Only include fields that are in the query_fields list
query = Query(
**{
key: getattr(query, key)
for key in query_fields
if hasattr(query, key)
}
)
dashboard_element: Optional[
LookerDashboardElement

View File

@ -311,7 +311,8 @@ def setup_mock_look(mocked_client):
)
]
mocked_client.query.return_value = Query(
mocked_client.look.return_value = LookWithQuery(
query=Query(
id="1",
view="sales_explore",
model="sales_model",
@ -321,6 +322,7 @@ def setup_mock_look(mocked_client):
dynamic_fields=None,
filters=None,
)
)
def setup_mock_soft_deleted_look(mocked_client):