dbt-common 0.1.3__py3-none-any.whl → 0.1.5__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 = "0.1.3"
1
+ version = "0.1.5"
dbt_common/context.py CHANGED
@@ -1,4 +1,4 @@
1
- from contextvars import ContextVar
1
+ from contextvars import ContextVar, copy_context
2
2
  from typing import List, Mapping, Optional
3
3
 
4
4
  from dbt_common.constants import SECRET_ENV_PREFIX
@@ -26,10 +26,23 @@ class InvocationContext:
26
26
  _INVOCATION_CONTEXT_VAR: ContextVar[InvocationContext] = ContextVar("DBT_INVOCATION_CONTEXT_VAR")
27
27
 
28
28
 
29
+ def reliably_get_invocation_var() -> ContextVar:
30
+ invocation_var: Optional[ContextVar] = next(
31
+ (cv for cv in copy_context() if cv.name == _INVOCATION_CONTEXT_VAR.name), None
32
+ )
33
+
34
+ if invocation_var is None:
35
+ invocation_var = _INVOCATION_CONTEXT_VAR
36
+
37
+ return invocation_var
38
+
39
+
29
40
  def set_invocation_context(env: Mapping[str, str]) -> None:
30
- _INVOCATION_CONTEXT_VAR.set(InvocationContext(env))
41
+ invocation_var = reliably_get_invocation_var()
42
+ invocation_var.set(InvocationContext(env))
31
43
 
32
44
 
33
45
  def get_invocation_context() -> InvocationContext:
34
- ctx = _INVOCATION_CONTEXT_VAR.get()
46
+ invocation_var = reliably_get_invocation_var()
47
+ ctx = invocation_var.get()
35
48
  return ctx
@@ -132,13 +132,6 @@ def fire_event_if(
132
132
  fire_event(lazy_e(), level=level)
133
133
 
134
134
 
135
- # a special case of fire_event_if, to only fire events in our unit/functional tests
136
- def fire_event_if_test(
137
- lazy_e: Callable[[], BaseEvent], level: Optional[EventLevel] = None
138
- ) -> None:
139
- fire_event_if(conditional=("pytest" in sys.modules), lazy_e=lazy_e, level=level)
140
-
141
-
142
135
  # top-level method for accessing the new eventing system
143
136
  # this is where all the side effects happen branched by event type
144
137
  # (i.e. - mutating the event history, printing to stdout, logging
@@ -1,7 +1,10 @@
1
1
  import concurrent.futures
2
2
  from contextlib import contextmanager
3
+ from contextvars import ContextVar
3
4
  from typing import Protocol, Optional
4
5
 
6
+ from dbt_common.context import get_invocation_context, reliably_get_invocation_var
7
+
5
8
 
6
9
  class ConnectingExecutor(concurrent.futures.Executor):
7
10
  def submit_connected(self, adapter, conn_name, func, *args, **kwargs):
@@ -60,8 +63,17 @@ class HasThreadingConfig(Protocol):
60
63
  threads: Optional[int]
61
64
 
62
65
 
66
+ def _thread_initializer(invocation_context: ContextVar) -> None:
67
+ invocation_var = reliably_get_invocation_var()
68
+ invocation_var.set(invocation_context)
69
+
70
+
63
71
  def executor(config: HasThreadingConfig) -> ConnectingExecutor:
64
72
  if config.args.single_threaded:
65
73
  return SingleThreadedExecutor()
66
74
  else:
67
- return MultiThreadedExecutor(max_workers=config.threads)
75
+ return MultiThreadedExecutor(
76
+ max_workers=config.threads,
77
+ initializer=_thread_initializer,
78
+ initargs=(get_invocation_context(),),
79
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dbt-common
3
- Version: 0.1.3
3
+ Version: 0.1.5
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,7 +1,7 @@
1
- dbt_common/__about__.py,sha256=-nFBox60-Jsr0CGYZKCL_Z7JdKnR04wJVcsqACtoUaI,18
1
+ dbt_common/__about__.py,sha256=P4QVYS_PjOFh5NqXToCnBO5ztkaEXiPmgf0LfaGzTcM,18
2
2
  dbt_common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  dbt_common/constants.py,sha256=DJIVuTBl5OZpjdFINHon8MNj_XT-Rrp41dAoAuQL2QI,38
4
- dbt_common/context.py,sha256=r4LJR09L4zw6uYGN8DPvE7IGwOqxl3FPM5G5HnnDCok,1054
4
+ dbt_common/context.py,sha256=XaxjooEU8uHp61TZqZ9jGmKtjjQm81nxJnSjdJmEo8E,1453
5
5
  dbt_common/dataclass_schema.py,sha256=CRSQQmzY4QIBzL54aomPT34o3u8T6Zu6W1XZmWfKs-A,5254
6
6
  dbt_common/helper_types.py,sha256=jW5Yv0Gwx4M14IEX4RID7k4s0hJiKHIzU8CxACQ1Y7k,3491
7
7
  dbt_common/invocation.py,sha256=Zw8jRPn75oi2VrUD6qGvaCDtSyIfqm5pJlPpRjs3s1E,202
@@ -30,7 +30,7 @@ dbt_common/events/event_handler.py,sha256=jfi0PyqIOGnXCG9HEa0VIVULqNvXs1RYmAg0b5
30
30
  dbt_common/events/event_manager.py,sha256=ZXJ-N4NsfQTnkEpvuedTjHD8Gt8DgYHbz601eTVCm-o,2175
31
31
  dbt_common/events/event_manager_client.py,sha256=etDlUv-3iIwM5IXXuzc1cmQID2fHOXw8dE9snp39-jk,1014
32
32
  dbt_common/events/format.py,sha256=x1RWDZ8G7ZMHmxdld6Q4VXca4kvnhiQOIaQXkC6Uo0Q,1609
33
- dbt_common/events/functions.py,sha256=z6QVFRAv7HdtzyOxcdkWdOeY_tUkkx_HPDLKCM44hkY,5034
33
+ dbt_common/events/functions.py,sha256=TfHUn8nfosEGfIik4pyDDnJDI0HrQ899eH9DiVdINJQ,4756
34
34
  dbt_common/events/helpers.py,sha256=CfsWwNDjsLJkPIgOtAfuLEnZ3rGUKeYsH8aDtCW12OA,410
35
35
  dbt_common/events/interfaces.py,sha256=hEDeDoB0FW2RYHVZBG7gebEt_mUVBzkn1yPubpaxs-s,147
36
36
  dbt_common/events/logger.py,sha256=6LLH8aLoRziFLBmwu-TCR5-EMpBtD28pSaL0FmKpeGA,6159
@@ -51,10 +51,10 @@ dbt_common/utils/casting.py,sha256=TVWHO5ct-foNBH-pj4vDZ84jVU-hPQll52X9YSjz2Zs,6
51
51
  dbt_common/utils/connection.py,sha256=J5zxWFpGHpUbe-F04S9bVLLO3HLvHB6INOkAey0k76c,1373
52
52
  dbt_common/utils/dict.py,sha256=unI-kJs2yvw7ic2U71-6H8koVRknkb0jCk7W_FCq6_I,4014
53
53
  dbt_common/utils/encoding.py,sha256=6_kSY2FvGNYMg7oX7PrbvVioieydih3Kl7Ii802LaHI,1705
54
- dbt_common/utils/executor.py,sha256=f8TqNi8PpRI-lC0Qu2Mlfi5BeJEn-Vgk4PM_FnO94dU,2016
54
+ dbt_common/utils/executor.py,sha256=W-DtjSPdbnm5bssT3EUo6SbGVi3VePD4LcvgKH1NhZM,2414
55
55
  dbt_common/utils/formatting.py,sha256=JUn5rzJ-uajs9wPCN0-f2iRFY1pOJF5YjTD9dERuLoc,165
56
56
  dbt_common/utils/jinja.py,sha256=XNfZHuZhLM_R_yPmzYojPm6bF7QOoxIjSWrkJRw6wks,965
57
- dbt_common-0.1.3.dist-info/METADATA,sha256=n4mFnZzRhtMK8I9_uQY07szZ3Aiuny-TttOdJHXXeBY,3648
58
- dbt_common-0.1.3.dist-info/WHEEL,sha256=TJPnKdtrSue7xZ_AVGkp9YXcvDrobsjBds1du3Nx6dc,87
59
- dbt_common-0.1.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
60
- dbt_common-0.1.3.dist-info/RECORD,,
57
+ dbt_common-0.1.5.dist-info/METADATA,sha256=EUQG5E4N0_IWbAqrYj3gjoA6Fq2LD0tguh-qzyzb7pI,3648
58
+ dbt_common-0.1.5.dist-info/WHEEL,sha256=TJPnKdtrSue7xZ_AVGkp9YXcvDrobsjBds1du3Nx6dc,87
59
+ dbt_common-0.1.5.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
60
+ dbt_common-0.1.5.dist-info/RECORD,,