Skip to content

Commit

Permalink
conditionally import deepdiff (#164)
Browse files Browse the repository at this point in the history
only import deepdiff when needed
  • Loading branch information
emmyoop authored Jul 9, 2024
1 parent feda22d commit 79e5fd1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions dbt_common/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import json
import os

from deepdiff import DeepDiff # type: ignore
from enum import Enum
from typing import Any, Callable, Dict, List, Mapping, Optional, Type

Expand Down Expand Up @@ -52,6 +51,11 @@ def from_dict(cls, dct: Mapping) -> "Record":

class Diff:
def __init__(self, current_recording_path: str, previous_recording_path: str) -> None:
# deepdiff is expensive to import, so we only do it here when we need it
from deepdiff import DeepDiff # type: ignore

self.diff = DeepDiff

self.current_recording_path = current_recording_path
self.previous_recording_path = previous_recording_path

Expand All @@ -67,7 +71,7 @@ def diff_query_records(self, current: List, previous: List) -> Dict[str, Any]:
if previous[i].get("result").get("table") is not None:
previous[i]["result"]["table"] = json.loads(previous[i]["result"]["table"])

return DeepDiff(previous, current, ignore_order=True, verbose_level=2)
return self.diff(previous, current, ignore_order=True, verbose_level=2)

def diff_env_records(self, current: List, previous: List) -> Dict[str, Any]:
# The mode and filepath may change. Ignore them.
Expand All @@ -77,12 +81,12 @@ def diff_env_records(self, current: List, previous: List) -> Dict[str, Any]:
"root[0]['result']['env']['DBT_RECORDER_MODE']",
]

return DeepDiff(
return self.diff(
previous, current, ignore_order=True, verbose_level=2, exclude_paths=exclude_paths
)

def diff_default(self, current: List, previous: List) -> Dict[str, Any]:
return DeepDiff(previous, current, ignore_order=True, verbose_level=2)
return self.diff(previous, current, ignore_order=True, verbose_level=2)

def calculate_diff(self) -> Dict[str, Any]:
with open(self.current_recording_path) as current_recording:
Expand Down

0 comments on commit 79e5fd1

Please sign in to comment.