Skip to content

Commit 81d9764

Browse files
Merge pull request #340 from microsoft/v1.9.8
V1.9.8
2 parents 67cab02 + bb3dbe7 commit 81d9764

File tree

7 files changed

+64
-10
lines changed

7 files changed

+64
-10
lines changed

dbt/adapters/fabric/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "1.9.7"
1+
version = "1.9.8"

dbt/adapters/fabric/fabric_connection_manager.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def _run_start_action(credentials: FabricCredentials) -> Dict[str, Any]:
354354
access_token = AZURE_AUTH_FUNCTIONS[credentials.authentication.lower()](
355355
credentials, POWER_BI_CREDENTIAL_SCOPE
356356
).token
357-
_snapshot_manager = wh_snapshot_manager(workspace_id, access_token)
357+
_snapshot_manager = wh_snapshot_manager(workspace_id, access_token, credentials.api_url)
358358

359359
if credentials.warehouse_snapshot_name is None:
360360
logger.info(
@@ -372,15 +372,53 @@ def _run_start_action(credentials: FabricCredentials) -> Dict[str, Any]:
372372
raise e
373373

374374

375+
def get_dbt_run_status() -> str:
376+
"""
377+
Get simple status of dbt run: 'success', 'error', or 'unknown'
378+
"""
379+
import json
380+
from pathlib import Path
381+
382+
try:
383+
run_results_path = Path("target/run_results.json")
384+
385+
if not run_results_path.exists():
386+
return "unknown"
387+
388+
with open(run_results_path, "r") as f:
389+
run_results = json.load(f)
390+
391+
results = run_results.get("results", [])
392+
393+
if not results:
394+
return "unknown"
395+
396+
# Check if any result has error status
397+
has_errors = any(result.get("status") == "error" for result in results)
398+
399+
return "error" if has_errors else "success"
400+
401+
except Exception:
402+
return "unknown"
403+
404+
375405
def _run_end_action(snapshot_result: Optional[Dict[str, Any]] = None):
376406
"""Enhanced run end action with snapshot result."""
377407
global _snapshot_manager
378408

409+
# Get simple status
410+
status = get_dbt_run_status()
411+
412+
if status != "success":
413+
logger.info(f"Skipping warehouse snapshot update: {status}")
414+
return
415+
379416
try:
380417
if snapshot_result and _snapshot_manager is not None:
381418
print(
382419
"Updating warehouse snapshot timestamp at end of run...",
383420
snapshot_result["displayName"],
421+
snapshot_result["snapshot_id"],
384422
)
385423
_snapshot_manager.update_warehouse_snapshot(snapshot_id=snapshot_result["snapshot_id"])
386424
except Exception as e:

dbt/adapters/fabric/fabric_credentials.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class FabricCredentials(Credentials):
3131
warehouse_snapshot_name: Optional[str] = None
3232
warehouse_snapshot_id: Optional[str] = None
3333
snapshot_timestamp: Optional[str] = None
34+
api_url: Optional[str] = "https://api.fabric.microsoft.com/v1"
3435

3536
_ALIASES = {
3637
"user": "UID",
@@ -47,6 +48,7 @@ class FabricCredentials(Credentials):
4748
"SQL_ATTR_TRACE": "trace_flag",
4849
"workspace_id": "workspace_id",
4950
"warehouse_snapshot_name": "warehouse_snapshot_name",
51+
"api_url": "api_url",
5052
}
5153

5254
@property
@@ -89,6 +91,7 @@ def _connection_keys(self):
8991
"trace_flag",
9092
"encrypt",
9193
"trust_cert",
94+
"api_url",
9295
)
9396

9497
@property

dbt/adapters/fabric/warehouse_snapshots.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99
class WarehouseSnapshotManager:
1010
"""Manager for Microsoft Fabric warehouse snapshots."""
1111

12-
def __init__(self, workspace_id: Optional[str], access_token: str):
12+
def __init__(
13+
self,
14+
workspace_id: Optional[str],
15+
access_token: str,
16+
base_url: Optional[str] = "https://api.fabric.microsoft.com/v1",
17+
):
1318
self.workspace_id = workspace_id
14-
self.base_url = "https://msitapi.fabric.microsoft.com/v1"
19+
self.base_url = base_url
1520
self.headers = {
1621
"Authorization": f"Bearer {access_token}",
1722
"Content-Type": "application/json",
@@ -29,7 +34,7 @@ def list_warehouses(self) -> List[Dict[str, Any]]:
2934
data = response.json()
3035
warehouses = data.get("value", [])
3136

32-
logger.info(f"Found {len(warehouses)} warehouses in workspace {self.workspace_id}")
37+
logger.debug(f"Found {len(warehouses)} warehouses in workspace {self.workspace_id}")
3338
return warehouses
3439

3540
except requests.exceptions.RequestException as e:
@@ -71,7 +76,7 @@ def list_warehouse_snapshots(self) -> List[Dict[str, Any]]:
7176
data = response.json()
7277
snapshots = data.get("value", [])
7378

74-
logger.info(
79+
logger.debug(
7580
f"Found {len(snapshots)} warehouse snapshots in workspace {self.workspace_id}"
7681
)
7782
return snapshots
@@ -94,23 +99,23 @@ def _poll_operation_status(
9499
import time
95100

96101
for attempt in range(max_retries):
97-
logger.info(
102+
logger.debug(
98103
f"Polling operation {operation_id}, attempt {attempt + 1}/{max_retries}"
99104
)
100105

101106
response = requests.get(operation_url, headers=self.headers)
102107

103108
if response.status_code == 201:
104109
# Operation is complete - get the result
105-
logger.info(f"Operation {operation_id} completed (201)")
110+
logger.debug(f"Operation {operation_id} completed (201)")
106111

107112
# Fetch the actual result from /result endpoint
108113
result_url = f"{operation_url}/result"
109114
result_response = requests.get(result_url, headers=self.headers)
110115
result_response.raise_for_status()
111116

112117
result = result_response.json()
113-
logger.info(f"Operation {operation_id} result retrieved successfully")
118+
logger.debug(f"Operation {operation_id} result retrieved successfully")
114119
return result
115120

116121
elif response.status_code == 200:

dbt/include/fabric/macros/adapters/columns.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
row_number() over (partition by object_name(c.object_id) order by c.column_id) as ordinal_position,
1616
c.name collate database_default as column_name,
1717
t.name as data_type,
18-
c.max_length as character_maximum_length,
18+
case
19+
when (t.name in ('nchar', 'nvarchar', 'sysname') and c.max_length <> -1) then c.max_length / 2
20+
else c.max_length
21+
end as character_maximum_length,
1922
c.precision as numeric_precision,
2023
c.scale as numeric_scale
2124
from sys.columns c {{ information_schema_hints() }}

dbt/include/fabric/macros/materializations/snapshots/helpers.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
{% else %}
5151
{{ columns.dbt_valid_to }} is null
5252
{% endif %}
53+
{%- if strategy.hard_deletes == 'new_record' -%}
54+
and {{ columns.dbt_is_deleted }} = 'False'
55+
{% endif -%}
5356
),
5457
insertions_source_data as (
5558
select *,

tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def _profile_ci_azure_base():
5858
"encrypt": True,
5959
"trust_cert": True,
6060
"trace_flag": False,
61+
"api_url": "https://msitapi.fabric.microsoft.com/v1",
6162
},
6263
}
6364

@@ -98,6 +99,7 @@ def _profile_user_azure():
9899
"encrypt": True,
99100
"trust_cert": True,
100101
"database": os.getenv("FABRIC_TEST_DBNAME"),
102+
"api_url": "https://msitapi.fabric.microsoft.com/v1",
101103
},
102104
}
103105
return profile

0 commit comments

Comments
 (0)