Skip to content

Commit 060a3ef

Browse files
committed
[DCV-3760] Refresh profiles.yml resolution on config reparse
1 parent 103f84c commit 060a3ef

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/dbt_core_interface/project.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,10 @@ def parse_project(
519519
) -> None:
520520
"""Parse the dbt project and load manifest."""
521521
if reparse_configuration:
522+
self._args = dc_replace(
523+
self._args,
524+
profiles_dir=_get_profiles_dir(self.project_root),
525+
)
522526
self.runtime_config = RuntimeConfig.from_args(self._args)
523527
self.__manifest_loader = ManifestLoader(
524528
self.runtime_config,

src/dbt_core_interface/watcher.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from __future__ import annotations
55

66
import logging
7+
import os
78
import threading
89
import typing as t
910
import weakref
@@ -123,6 +124,16 @@ def _monitor_loop(self) -> None:
123124

124125
_ = self._stop_event.wait(self.check_interval)
125126

127+
def _all_profiles_yml_paths(self) -> list[Path]:
128+
"""Return all potential profiles.yml paths in priority order."""
129+
paths = []
130+
env_dir = os.environ.get("DBT_PROFILES_DIR")
131+
if env_dir:
132+
paths.append(Path(env_dir).expanduser().resolve() / "profiles.yml")
133+
paths.append(self._project_or_raise.project_root / "profiles.yml")
134+
paths.append(Path.home() / ".dbt" / "profiles.yml")
135+
return paths
136+
126137
def _initialize_file_mtimes(self) -> None:
127138
"""Initialize the file modification time tracking."""
128139
for f_proxy in self._project_or_raise.manifest.files.values():
@@ -132,9 +143,8 @@ def _initialize_file_mtimes(self) -> None:
132143
self._mtimes[self._project_or_raise.dbt_project_yml] = (
133144
self._project_or_raise.dbt_project_yml.stat().st_mtime
134145
)
135-
self._mtimes[self._project_or_raise.profiles_yml] = (
136-
self._project_or_raise.profiles_yml.stat().st_mtime
137-
)
146+
for path in self._all_profiles_yml_paths():
147+
self._mtimes[path] = path.stat().st_mtime if path.exists() else 0.0
138148
logger.debug(f"Initialized tracking for {len(self._mtimes)} files")
139149

140150
def _check_for_changes(self) -> int:
@@ -143,11 +153,12 @@ def _check_for_changes(self) -> int:
143153
A return value of 0 means no changes, 1 means files were added/removed, and 2 means
144154
a configuration file was modified (dbt_project.yml or profiles.yml).
145155
"""
146-
for path in (self._project_or_raise.dbt_project_yml, self._project_or_raise.profiles_yml):
156+
config_paths = [self._project_or_raise.dbt_project_yml, *self._all_profiles_yml_paths()]
157+
for path in config_paths:
147158
try:
148159
current_mtime = path.stat().st_mtime if path.exists() else 0.0
149160
stamped_mtime = self._mtimes.get(path)
150-
if stamped_mtime is None or current_mtime > stamped_mtime:
161+
if stamped_mtime is None or current_mtime != stamped_mtime:
151162
self._mtimes[path] = current_mtime
152163
return 2
153164
except OSError as e:

0 commit comments

Comments
 (0)