Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove dbt.flags.LOG_CACHE_EVENTS usage in dbt/adapters #8933

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20231101-173124.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: 'Remove usage of dbt.flags.LOG_CACHE_EVENTS in dbt/adapters'
time: 2023-11-01T17:31:24.974093-04:00
custom:
Author: michelleark
Issue: "8969"
2 changes: 1 addition & 1 deletion core/dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class BaseAdapter(metaclass=AdapterMeta):

def __init__(self, config, mp_context: SpawnContext) -> None:
self.config = config
self.cache = RelationsCache()
self.cache = RelationsCache(log_cache_events=config.log_cache_events)
self.connections = self.ConnectionManager(config, mp_context)
self._macro_manifest_lazy: Optional[MacroManifest] = None

Expand Down
14 changes: 6 additions & 8 deletions core/dbt/adapters/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
)
from dbt.common.events.functions import fire_event, fire_event_if
from dbt.common.events.types import CacheAction, CacheDumpGraph
from dbt.flags import get_flags
from dbt.utils import lowercase


Expand Down Expand Up @@ -165,10 +164,11 @@ class RelationsCache:
:attr Set[str] schemas: The set of known/cached schemas, all lowercased.
"""

def __init__(self) -> None:
def __init__(self, log_cache_events: bool = False) -> None:
self.relations: Dict[_ReferenceKey, _CachedRelation] = {}
self.lock = threading.RLock()
self.schemas: Set[Tuple[Optional[str], Optional[str]]] = set()
self.log_cache_events = log_cache_events

def add_schema(
self,
Expand Down Expand Up @@ -318,18 +318,17 @@ def add(self, relation):

:param BaseRelation relation: The underlying relation.
"""
flags = get_flags()
cached = _CachedRelation(relation)
fire_event_if(
flags.LOG_CACHE_EVENTS,
self.log_cache_events,
lambda: CacheDumpGraph(before_after="before", action="adding", dump=self.dump_graph()),
)
fire_event(CacheAction(action="add_relation", ref_key=_make_ref_key_dict(cached)))

with self.lock:
self._setdefault(cached)
fire_event_if(
flags.LOG_CACHE_EVENTS,
self.log_cache_events,
lambda: CacheDumpGraph(before_after="after", action="adding", dump=self.dump_graph()),
)

Expand Down Expand Up @@ -454,9 +453,8 @@ def rename(self, old, new):
ref_key_2=new_key._asdict(),
)
)
flags = get_flags()
fire_event_if(
flags.LOG_CACHE_EVENTS,
self.log_cache_events,
lambda: CacheDumpGraph(before_after="before", action="rename", dump=self.dump_graph()),
)

Expand All @@ -467,7 +465,7 @@ def rename(self, old, new):
self._setdefault(_CachedRelation(new))

fire_event_if(
flags.LOG_CACHE_EVENTS,
self.log_cache_events,
lambda: CacheDumpGraph(before_after="after", action="rename", dump=self.dump_graph()),
)

Expand Down
1 change: 1 addition & 0 deletions core/dbt/adapters/contracts/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,4 @@ class AdapterRequiredConfig(HasCredentials, Protocol):
query_comment: QueryComment
cli_vars: Dict[str, Any]
target_path: str
log_cache_events: bool
4 changes: 4 additions & 0 deletions core/dbt/config/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Profile(HasCredentials):
threads: int
credentials: Credentials
profile_env_vars: Dict[str, Any]
log_cache_events: bool

def __init__(
self,
Expand All @@ -93,6 +94,9 @@ def __init__(
self.threads = threads
self.credentials = credentials
self.profile_env_vars = {} # never available on init
self.log_cache_events = (
get_flags().LOG_CACHE_EVENTS
) # never available on init, set for adapter instantiation via AdapterRequiredConfig

def to_profile_info(self, serialize_credentials: bool = False) -> Dict[str, Any]:
"""Unlike to_project_config, this dict is not a mirror of any existing
Expand Down
2 changes: 2 additions & 0 deletions core/dbt/config/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def from_parts(
).to_dict(omit_none=True)

cli_vars: Dict[str, Any] = getattr(args, "vars", {})
log_cache_events: bool = getattr(args, "log_cache_events", profile.log_cache_events)

return cls(
project_name=project.project_name,
Expand Down Expand Up @@ -183,6 +184,7 @@ def from_parts(
credentials=profile.credentials,
args=args,
cli_vars=cli_vars,
log_cache_events=log_cache_events,
dependencies=dependencies,
dbt_cloud=project.dbt_cloud,
)
Expand Down