|
1 | 1 | from sempy_labs._helper_functions import ( |
| 2 | + resolve_item_id, |
| 3 | + resolve_workspace_id, |
2 | 4 | resolve_workspace_name_and_id, |
3 | 5 | resolve_item_name_and_id, |
4 | 6 | _base_api, |
|
8 | 10 | from sempy._utils._log import log |
9 | 11 | import sempy_labs._icons as icons |
10 | 12 | from uuid import UUID |
| 13 | +import sempy.fabric as fabric |
11 | 14 |
|
12 | 15 |
|
13 | 16 | @log |
@@ -108,57 +111,40 @@ def report_rebind_all( |
108 | 111 | the new semantic model. |
109 | 112 | """ |
110 | 113 |
|
111 | | - from sempy_labs._list_functions import list_reports_using_semantic_model |
112 | | - |
113 | | - (dataset_name, dataset_id) = resolve_dataset_name_and_id( |
114 | | - dataset=dataset, workspace=dataset_workspace |
| 114 | + (dataset_name, dataset_id) = resolve_item_name_and_id( |
| 115 | + item=dataset, type="SemanticModel", workspace=dataset_workspace |
115 | 116 | ) |
116 | | - (new_dataset_name, new_dataset_id) = resolve_dataset_name_and_id( |
117 | | - dataset=new_dataset, workspace=new_dataset_workspace |
| 117 | + new_dataset_id = resolve_item_id( |
| 118 | + item=new_dataset, type="SemanticModel", workspace=new_dataset_workspace |
118 | 119 | ) |
119 | 120 |
|
120 | 121 | if dataset_id == new_dataset_id: |
121 | 122 | raise ValueError( |
122 | | - f"{icons.red_dot} The 'dataset' and 'new_dataset' parameters are both set to '{dataset}'. These parameters must be set to different values." |
| 123 | + f"{icons.red_dot} The 'dataset' and 'new_dataset' parameters are both set to the same semantic model within the same workspace. These parameters must be set to different values." |
123 | 124 | ) |
124 | | - (dataset_workspace_name, dataset_workspace_id) = resolve_workspace_name_and_id( |
125 | | - workspace=dataset_workspace |
126 | | - ) |
| 125 | + dataset_workspace_id = resolve_workspace_id(workspace=dataset_workspace) |
127 | 126 |
|
128 | | - if isinstance(report_workspace, str): |
| 127 | + if isinstance(report_workspace, str) or report_workspace is None: |
129 | 128 | report_workspace = [report_workspace] |
130 | 129 |
|
131 | | - dfR = list_reports_using_semantic_model( |
132 | | - dataset=dataset, workspace=dataset_workspace |
133 | | - ) |
134 | | - |
135 | | - if dfR.empty: |
136 | | - print( |
137 | | - f"{icons.info} The '{dataset_name}' semantic model within the '{dataset_workspace_name}' workspace has no dependent reports." |
138 | | - ) |
139 | | - return |
140 | | - |
141 | | - if report_workspace is None: |
142 | | - dfR_filt = dfR.copy() |
143 | | - else: |
| 130 | + for w in report_workspace: |
| 131 | + dfR = fabric.list_reports(workspace=w) |
144 | 132 | dfR_filt = dfR[ |
145 | | - (dfR["Report Workspace Name"].isin(report_workspace)) |
146 | | - | (dfR["Report Workspace ID"].isin(report_workspace)) |
| 133 | + (dfR["Dataset ID"] == dataset_id) |
| 134 | + & (dfR["Dataset Workspace Id"] == dataset_workspace_id) |
147 | 135 | ] |
148 | | - |
149 | | - if dfR_filt.empty: |
150 | | - print( |
151 | | - f"{icons.info} No reports found for the '{dataset_name}' semantic model within the '{dataset_workspace_name}' workspace." |
152 | | - ) |
153 | | - return |
154 | | - |
155 | | - for _, r in dfR_filt.iterrows(): |
156 | | - rpt_name = r["Report Name"] |
157 | | - rpt_wksp = r["Report Workspace Name"] |
158 | | - |
159 | | - report_rebind( |
160 | | - report=rpt_name, |
161 | | - dataset=new_dataset, |
162 | | - report_workspace=rpt_wksp, |
163 | | - dataset_workspace=new_dataset_workspace, |
164 | | - ) |
| 136 | + if dfR_filt.empty: |
| 137 | + (wksp_name, _) = resolve_workspace_name_and_id(workspace=w) |
| 138 | + print( |
| 139 | + f"{icons.info} No reports found for the '{dataset_name}' semantic model within the '{wksp_name}' workspace." |
| 140 | + ) |
| 141 | + else: |
| 142 | + # Rebind reports to new dataset |
| 143 | + for _, r in dfR_filt.iterrows(): |
| 144 | + rpt_name = r["Name"] |
| 145 | + report_rebind( |
| 146 | + report=rpt_name, |
| 147 | + dataset=new_dataset, |
| 148 | + report_workspace=w, |
| 149 | + dataset_workspace=new_dataset_workspace, |
| 150 | + ) |
0 commit comments