dbt-common 1.15.0__py3-none-any.whl → 1.16.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
dbt_common/__about__.py CHANGED
@@ -1 +1 @@
1
- version = "1.15.0"
1
+ version = "1.16.0"
dbt_common/context.py CHANGED
@@ -43,6 +43,12 @@ class InvocationContext:
43
43
  self._env_secrets: Optional[List[str]] = None
44
44
  self._env_private = env_private
45
45
  self.recorder: Optional[Recorder] = None
46
+
47
+ # If set to True later, this flag will prevent dbt from creating a new
48
+ # invocation context for every invocation, which is useful for testing
49
+ # scenarios.
50
+ self.do_not_reset = False
51
+
46
52
  # This class will also eventually manage the invocation_id, flags, event manager, etc.
47
53
 
48
54
  @property
@@ -85,3 +91,10 @@ def get_invocation_context() -> InvocationContext:
85
91
  invocation_var = reliably_get_invocation_var()
86
92
  ctx = invocation_var.get()
87
93
  return ctx
94
+
95
+
96
+ def try_get_invocation_context() -> Optional[InvocationContext]:
97
+ try:
98
+ return get_invocation_context()
99
+ except Exception:
100
+ return None
dbt_common/record.py CHANGED
@@ -12,13 +12,16 @@ import json
12
12
  import os
13
13
 
14
14
  from enum import Enum
15
+ from threading import Lock
15
16
  from typing import Any, Callable, Dict, List, Mapping, Optional, TextIO, Tuple, Type
16
- import contextvars
17
17
 
18
18
  from mashumaro import field_options
19
19
  from mashumaro.mixins.json import DataClassJSONMixin
20
20
  from mashumaro.types import SerializationStrategy
21
21
 
22
+ import contextvars
23
+
24
+
22
25
  RECORDED_BY_HIGHER_FUNCTION = contextvars.ContextVar("RECORDED_BY_HIGHER_FUNCTION", default=False)
23
26
 
24
27
 
@@ -31,9 +34,10 @@ class Record:
31
34
  result_cls: Optional[type] = None
32
35
  group: Optional[str] = None
33
36
 
34
- def __init__(self, params, result) -> None:
37
+ def __init__(self, params, result, seq=None) -> None:
35
38
  self.params = params
36
39
  self.result = result
40
+ self.seq = seq
37
41
 
38
42
  def to_dict(self) -> Dict[str, Any]:
39
43
  return {
@@ -45,6 +49,7 @@ class Record:
45
49
  else dataclasses.asdict(self.result)
46
50
  if self.result is not None
47
51
  else None,
52
+ "seq": self.seq,
48
53
  }
49
54
 
50
55
  @classmethod
@@ -61,7 +66,8 @@ class Record:
61
66
  if cls.result_cls is not None
62
67
  else None
63
68
  )
64
- return cls(params=p, result=r)
69
+ s = dct.get("seq", None)
70
+ return cls(params=p, result=r, seq=s)
65
71
 
66
72
 
67
73
  class Diff:
@@ -167,6 +173,9 @@ class Recorder:
167
173
  if self.mode == RecorderMode.REPLAY:
168
174
  self._unprocessed_records_by_type = self.load(self.previous_recording_path)
169
175
 
176
+ self._counter = 0
177
+ self._counter_lock = Lock()
178
+
170
179
  @classmethod
171
180
  def register_record_type(cls, rec_type) -> Any:
172
181
  cls._record_cls_by_name[rec_type.__name__] = rec_type
@@ -177,6 +186,11 @@ class Recorder:
177
186
  rec_cls_name = record.__class__.__name__ # type: ignore
178
187
  if rec_cls_name not in self._records_by_type:
179
188
  self._records_by_type[rec_cls_name] = []
189
+
190
+ with self._counter_lock:
191
+ record.seq = self._counter
192
+ self._counter += 1
193
+
180
194
  self._records_by_type[rec_cls_name].append(record)
181
195
 
182
196
  def pop_matching_record(self, params: Any) -> Optional[Record]:
@@ -199,21 +213,28 @@ class Recorder:
199
213
  return match
200
214
 
201
215
  def write_json(self, out_stream: TextIO):
202
- d = self._to_dict()
216
+ d = self._to_list()
203
217
  json.dump(d, out_stream)
204
218
 
205
219
  def write(self) -> None:
206
220
  with open(self.current_recording_path, "w") as file:
207
221
  self.write_json(file)
208
222
 
209
- def _to_dict(self) -> Dict:
210
- dct: Dict[str, Any] = {}
223
+ def _to_list(self) -> List[Dict]:
224
+ def get_tagged_dict(record: Record, record_type: str) -> Dict:
225
+ d = record.to_dict()
226
+ d["type"] = record_type
227
+ return d
211
228
 
229
+ record_list: List[Dict] = []
212
230
  for record_type in self._records_by_type:
213
- record_list = [r.to_dict() for r in self._records_by_type[record_type]]
214
- dct[record_type] = record_list
231
+ record_list.extend(
232
+ get_tagged_dict(r, record_type) for r in self._records_by_type[record_type]
233
+ )
234
+
235
+ record_list.sort(key=lambda r: r["seq"])
215
236
 
216
- return dct
237
+ return record_list
217
238
 
218
239
  @classmethod
219
240
  def load(cls, file_name: str) -> Dict[str, List[Dict[str, Any]]]:
@@ -340,6 +361,7 @@ def record_function(
340
361
  method: bool = False,
341
362
  tuple_result: bool = False,
342
363
  id_field_name: Optional[str] = None,
364
+ index_on_thread_id: bool = False,
343
365
  ) -> Callable:
344
366
  """This is the @record_function decorator, which marks functions which will
345
367
  have their function calls recorded during record mode, and mocked out with
@@ -351,7 +373,7 @@ def record_function(
351
373
  tuple_result,
352
374
  id_field_name,
353
375
  None,
354
- False,
376
+ index_on_thread_id,
355
377
  False,
356
378
  )
357
379
 
@@ -458,9 +480,16 @@ def _record_function_inner(
458
480
  param_args = args[1:] if method else args
459
481
  if method and id_field_name is not None:
460
482
  if index_on_thread_id:
461
- from dbt_common.context import get_invocation_context
483
+ from dbt_common.events.contextvars import get_node_info
484
+
485
+ node_info = get_node_info()
486
+ if node_info and "unique_id" in node_info:
487
+ thread_name = node_info["unique_id"]
488
+ else:
489
+ from dbt_common.context import get_invocation_context
462
490
 
463
- param_args = (get_invocation_context().name,) + param_args
491
+ thread_name = get_invocation_context().name
492
+ param_args = (thread_name,) + param_args
464
493
  else:
465
494
  param_args = (getattr(args[0], id_field_name),) + param_args
466
495
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dbt-common
3
- Version: 1.15.0
3
+ Version: 1.16.0
4
4
  Summary: The shared common utilities that dbt-core and adapter implementations use
5
5
  Project-URL: Homepage, https://github.com/dbt-labs/dbt-common
6
6
  Project-URL: Repository, https://github.com/dbt-labs/dbt-common.git
@@ -1,13 +1,13 @@
1
- dbt_common/__about__.py,sha256=ifS0ZWsb82NyM4xyQWKPKGKE5bG3EXlYHT1H7h1HxOY,19
1
+ dbt_common/__about__.py,sha256=6EsnLejJWxuMqRt_s2lK0ter3lZGaIm5OK1MPeLZC5M,19
2
2
  dbt_common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  dbt_common/behavior_flags.py,sha256=hQzxCqQSweJbRp_xoQqNnlUF77PBuOdCdLOSdcBlkxk,4885
4
4
  dbt_common/constants.py,sha256=-Y5DIL1SDPQWtlCNizXRYxFgbx1D7LaLs1ysamvGMRk,278
5
- dbt_common/context.py,sha256=tVeXtsptvuw7d8CvdlYSBFcKLyLZ852iQNwcxNmUzYY,2577
5
+ dbt_common/context.py,sha256=-ErtKG4xfOh1-Y569fwu6u2O381nRan18HhATrYDoZE,2950
6
6
  dbt_common/dataclass_schema.py,sha256=u2S0dxwxIghv8RMqC91HlWZJVxmsC_844yZQaGyOwdY,5563
7
7
  dbt_common/helper_types.py,sha256=FWJGPmp7Qp2iToHyI4uvhkBbu_d1tl2_oF-obi98_N4,3917
8
8
  dbt_common/invocation.py,sha256=xw0NBIE-6LHd135cx4non-MkGGsia0mYN0lMkmNEucE,435
9
9
  dbt_common/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- dbt_common/record.py,sha256=ExF8ccUpDv2kButAMnTR8zSyD9agU7nhXTKFDx7Iw7Y,19352
10
+ dbt_common/record.py,sha256=B5Ybpf-yzPRPyhxp4JNZyDAOGoSd2dr6VjLykH7VKN4,20247
11
11
  dbt_common/semver.py,sha256=Znewz6tc_NBpXr4mZf20bK_RayPL4ODrnxDbkUZrrRo,15034
12
12
  dbt_common/tests.py,sha256=6lC_JuRtoYO6cbAF8-R5aTM4HtQiM_EH8X5m_97duGY,315
13
13
  dbt_common/ui.py,sha256=rc2TEM29raBFc_LXcg901pMDD07C2ohwp9qzkE-7pBY,2567
@@ -57,7 +57,7 @@ dbt_common/utils/encoding.py,sha256=6_kSY2FvGNYMg7oX7PrbvVioieydih3Kl7Ii802LaHI,
57
57
  dbt_common/utils/executor.py,sha256=pNY0UbPlwQmTE69Vt_Rj91YGCIOEaqeYU3CjAds0T70,2454
58
58
  dbt_common/utils/formatting.py,sha256=JUn5rzJ-uajs9wPCN0-f2iRFY1pOJF5YjTD9dERuLoc,165
59
59
  dbt_common/utils/jinja.py,sha256=JXgNmJArGGy0h7qkbNLA3zaEQmoF1CxsNBYTlIwFXDw,1101
60
- dbt_common-1.15.0.dist-info/METADATA,sha256=gcyH_sfjldI5SpDsEGDig-tUAVMVANrqNEmN0jun2c0,4895
61
- dbt_common-1.15.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
62
- dbt_common-1.15.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
63
- dbt_common-1.15.0.dist-info/RECORD,,
60
+ dbt_common-1.16.0.dist-info/METADATA,sha256=k7yyMmWSYXvX-1bT5gzMUphCMcqntoMMloji1mnszvg,4895
61
+ dbt_common-1.16.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
62
+ dbt_common-1.16.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
63
+ dbt_common-1.16.0.dist-info/RECORD,,