Skip to content

Commit

Permalink
Set thread name based on node for record, when possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterallenwebb committed Mar 4, 2025
1 parent 2aa3379 commit 226e844
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions dbt_common/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,27 @@ def pop_matching_record(self, params: Any) -> Optional[Record]:
return match

def write_json(self, out_stream: TextIO):
d = self._to_dict()
d = self._to_list()
json.dump(d, out_stream)

def write(self) -> None:
with open(self.current_recording_path, "w") as file:
self.write_json(file)

def _to_dict(self) -> Dict:
dct: Dict[str, Any] = {}
def _to_list(self) -> List[Dict]:

def get_tagged_dict(record: Record, record_type: str) -> Dict :
d = record.to_dict()
d["type"] = record_type
return d

record_list: List[Dict] = []
for record_type in self._records_by_type:
record_list = [r.to_dict() for r in self._records_by_type[record_type]]
dct[record_type] = record_list
record_list.extend(get_tagged_dict(r, record_type) for r in self._records_by_type[record_type])

record_list.sort(key=lambda r: r["seq"])

return dct
return record_list

@classmethod
def load(cls, file_name: str) -> Dict[str, List[Dict[str, Any]]]:
Expand Down Expand Up @@ -470,9 +476,14 @@ def record_replay_wrapper(*args, **kwargs) -> Any:
param_args = args[1:] if method else args
if method and id_field_name is not None:
if index_on_thread_id:
from dbt_common.context import get_invocation_context

param_args = (get_invocation_context().name,) + param_args
from dbt_common.events.contextvars import get_node_info
node_info = get_node_info()
if node_info and "unique_id" in node_info:
thread_name = node_info["unique_id"]
else:
from dbt_common.context import get_invocation_context
thread_name = get_invocation_context().name
param_args = (thread_name,) + param_args
else:
param_args = (getattr(args[0], id_field_name),) + param_args

Expand Down

0 comments on commit 226e844

Please sign in to comment.