@@ -78,6 +78,16 @@ class PowerBIContentData:
78
78
properties : Dict [str , Any ]
79
79
80
80
81
+ @whitelist_for_serdes
82
+ @record
83
+ class PowerBITranslatorData (PowerBIContentData ):
84
+ """A record representing a piece of content in PowerBI and the PowerBI workspace data.
85
+ Includes the content's type and data as returned from the API.
86
+ """
87
+
88
+ workspace_data : "PowerBIWorkspaceData"
89
+
90
+
81
91
@whitelist_for_serdes
82
92
@record
83
93
class PowerBIWorkspaceData :
@@ -155,14 +165,8 @@ class DagsterPowerBITranslator:
155
165
Subclass this class to implement custom logic for each type of PowerBI content.
156
166
"""
157
167
158
- def __init__ (self , context : PowerBIWorkspaceData ):
159
- self ._context = context
160
-
161
- @property
162
- def workspace_data (self ) -> PowerBIWorkspaceData :
163
- return self ._context
164
-
165
168
def get_asset_spec (self , data : PowerBIContentData ) -> AssetSpec :
169
+ data = check .inst (data , PowerBITranslatorData )
166
170
if data .content_type == PowerBIContentType .DASHBOARD :
167
171
return self .get_dashboard_spec (data )
168
172
elif data .content_type == PowerBIContentType .REPORT :
@@ -179,20 +183,28 @@ def get_asset_spec(self, data: PowerBIContentData) -> AssetSpec:
179
183
additional_warn_text = "Use `DagsterPowerBITranslator.get_asset_spec(...).key` instead" ,
180
184
)
181
185
def get_dashboard_asset_key (self , data : PowerBIContentData ) -> AssetKey :
186
+ data = check .inst (data , PowerBITranslatorData )
182
187
return self .get_dashboard_spec (data ).key
183
188
184
189
def get_dashboard_spec (self , data : PowerBIContentData ) -> AssetSpec :
190
+ data = check .inst (data , PowerBITranslatorData )
185
191
dashboard_id = data .properties ["id" ]
186
192
tile_report_ids = [
187
193
tile ["reportId" ] for tile in data .properties ["tiles" ] if "reportId" in tile
188
194
]
189
195
report_keys = [
190
- self .get_report_spec (self .workspace_data .reports_by_id [report_id ]).key
196
+ self .get_report_spec (
197
+ PowerBITranslatorData (
198
+ content_type = data .workspace_data .reports_by_id [report_id ].content_type ,
199
+ properties = data .workspace_data .reports_by_id [report_id ].properties ,
200
+ workspace_data = data .workspace_data ,
201
+ )
202
+ ).key
191
203
for report_id in tile_report_ids
192
204
]
193
205
url = (
194
206
data .properties .get ("webUrl" )
195
- or f"https://app.powerbi.com/groups/{ self .workspace_data .workspace_id } /dashboards/{ dashboard_id } "
207
+ or f"https://app.powerbi.com/groups/{ data .workspace_data .workspace_id } /dashboards/{ dashboard_id } "
196
208
)
197
209
198
210
return AssetSpec (
@@ -213,18 +225,30 @@ def get_dashboard_spec(self, data: PowerBIContentData) -> AssetSpec:
213
225
additional_warn_text = "Use `DagsterPowerBITranslator.get_asset_spec(...).key` instead" ,
214
226
)
215
227
def get_report_asset_key (self , data : PowerBIContentData ) -> AssetKey :
228
+ data = check .inst (data , PowerBITranslatorData )
216
229
return self .get_report_spec (data ).key
217
230
218
231
def get_report_spec (self , data : PowerBIContentData ) -> AssetSpec :
232
+ data = check .inst (data , PowerBITranslatorData )
219
233
report_id = data .properties ["id" ]
220
234
dataset_id = data .properties .get ("datasetId" )
221
235
dataset_data = (
222
- self .workspace_data .semantic_models_by_id .get (dataset_id ) if dataset_id else None
236
+ data .workspace_data .semantic_models_by_id .get (dataset_id ) if dataset_id else None
237
+ )
238
+ dataset_key = (
239
+ self .get_semantic_model_spec (
240
+ PowerBITranslatorData (
241
+ content_type = dataset_data .content_type ,
242
+ properties = dataset_data .properties ,
243
+ workspace_data = data .workspace_data ,
244
+ )
245
+ ).key
246
+ if dataset_data
247
+ else None
223
248
)
224
- dataset_key = self .get_semantic_model_spec (dataset_data ).key if dataset_data else None
225
249
url = (
226
250
data .properties .get ("webUrl" )
227
- or f"https://app.powerbi.com/groups/{ self .workspace_data .workspace_id } /reports/{ report_id } "
251
+ or f"https://app.powerbi.com/groups/{ data .workspace_data .workspace_id } /reports/{ report_id } "
228
252
)
229
253
230
254
owner = data .properties .get ("createdBy" )
@@ -243,18 +267,26 @@ def get_report_spec(self, data: PowerBIContentData) -> AssetSpec:
243
267
additional_warn_text = "Use `DagsterPowerBITranslator.get_asset_spec(...).key` instead" ,
244
268
)
245
269
def get_semantic_model_asset_key (self , data : PowerBIContentData ) -> AssetKey :
270
+ data = check .inst (data , PowerBITranslatorData )
246
271
return self .get_semantic_model_spec (data ).key
247
272
248
273
def get_semantic_model_spec (self , data : PowerBIContentData ) -> AssetSpec :
274
+ data = check .inst (data , PowerBITranslatorData )
249
275
dataset_id = data .properties ["id" ]
250
276
source_ids = data .properties .get ("sources" , [])
251
277
source_keys = [
252
- self .get_data_source_spec (self .workspace_data .data_sources_by_id [source_id ]).key
278
+ self .get_data_source_spec (
279
+ PowerBITranslatorData (
280
+ content_type = data .workspace_data .data_sources_by_id [source_id ].content_type ,
281
+ properties = data .workspace_data .data_sources_by_id [source_id ].properties ,
282
+ workspace_data = data .workspace_data ,
283
+ )
284
+ ).key
253
285
for source_id in source_ids
254
286
]
255
287
url = (
256
288
data .properties .get ("webUrl" )
257
- or f"https://app.powerbi.com/groups/{ self .workspace_data .workspace_id } /datasets/{ dataset_id } "
289
+ or f"https://app.powerbi.com/groups/{ data .workspace_data .workspace_id } /datasets/{ dataset_id } "
258
290
)
259
291
260
292
for table in data .properties .get ("tables" , []):
@@ -297,9 +329,11 @@ def get_semantic_model_spec(self, data: PowerBIContentData) -> AssetSpec:
297
329
additional_warn_text = "Use `DagsterPowerBITranslator.get_asset_spec(...).key` instead" ,
298
330
)
299
331
def get_data_source_asset_key (self , data : PowerBIContentData ) -> AssetKey :
332
+ data = check .inst (data , PowerBITranslatorData )
300
333
return self .get_data_source_spec (data ).key
301
334
302
335
def get_data_source_spec (self , data : PowerBIContentData ) -> AssetSpec :
336
+ data = check .inst (data , PowerBITranslatorData )
303
337
connection_name = (
304
338
data .properties ["connectionDetails" ].get ("path" )
305
339
or data .properties ["connectionDetails" ].get ("url" )
0 commit comments