Skip to content

Commit 8225a00

Browse files
authored
Add deprecation warnings for log-path, target-path in dbt_project.yml (#7185)
* Add deprecation warnings for log-path, target-path in dbt_project.yml * Fix tests/unit/test_events * Fix failing tests * PR feedback
1 parent 9605b76 commit 8225a00

File tree

14 files changed

+151
-29
lines changed

14 files changed

+151
-29
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
kind: Breaking Changes
2+
body: Specifying "log-path" and "target-path" in "dbt_project.yml" is deprecated.
3+
This functionality will be removed in a future version of dbt-core. If you need
4+
to specify a custom path for logs or artifacts, please set via CLI flag or env var
5+
instead.
6+
time: 2023-03-17T11:00:33.448472+01:00
7+
custom:
8+
Author: jtcohen6
9+
Issue: "6882"

core/dbt/cli/flags.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ def assign_params(ctx, params_assigned_from_default, deprecated_env_vars):
222222
self._override_if_set("LOG_FORMAT", "LOG_FORMAT_FILE", params_assigned_from_default)
223223

224224
# Default LOG_PATH from PROJECT_DIR, if available.
225+
# Starting in v1.5, if `log-path` is set in `dbt_project.yml`, it will raise a deprecation warning,
226+
# with the possibility of removing it in a future release.
225227
if getattr(self, "LOG_PATH", None) is None:
226228
project_dir = getattr(self, "PROJECT_DIR", default_project_dir())
227229
version_check = getattr(self, "VERSION_CHECK", True)

core/dbt/config/project.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,23 +298,27 @@ def render_package_metadata(self, renderer: PackageRenderer) -> ProjectPackageMe
298298
raise DbtProjectError("Package dbt_project.yml must have a name!")
299299
return ProjectPackageMetadata(self.project_name, packages_config.packages)
300300

301-
def check_config_path(self, project_dict, deprecated_path, exp_path):
301+
def check_config_path(
302+
self, project_dict, deprecated_path, expected_path=None, default_value=None
303+
):
302304
if deprecated_path in project_dict:
303-
if exp_path in project_dict:
305+
if expected_path in project_dict:
304306
msg = (
305-
"{deprecated_path} and {exp_path} cannot both be defined. The "
306-
"`{deprecated_path}` config has been deprecated in favor of `{exp_path}`. "
307+
"{deprecated_path} and {expected_path} cannot both be defined. The "
308+
"`{deprecated_path}` config has been deprecated in favor of `{expected_path}`. "
307309
"Please update your `dbt_project.yml` configuration to reflect this "
308310
"change."
309311
)
310312
raise DbtProjectError(
311-
msg.format(deprecated_path=deprecated_path, exp_path=exp_path)
313+
msg.format(deprecated_path=deprecated_path, expected_path=expected_path)
314+
)
315+
# this field is no longer supported, but many projects may specify it with the default value
316+
# if so, let's only raise this deprecation warning if they set a custom value
317+
if not default_value or project_dict[deprecated_path] != default_value:
318+
deprecations.warn(
319+
f"project-config-{deprecated_path}",
320+
deprecated_path=deprecated_path,
312321
)
313-
deprecations.warn(
314-
f"project-config-{deprecated_path}",
315-
deprecated_path=deprecated_path,
316-
exp_path=exp_path,
317-
)
318322

319323
def create_project(self, rendered: RenderComponents) -> "Project":
320324
unrendered = RenderComponents(
@@ -329,6 +333,8 @@ def create_project(self, rendered: RenderComponents) -> "Project":
329333

330334
self.check_config_path(rendered.project_dict, "source-paths", "model-paths")
331335
self.check_config_path(rendered.project_dict, "data-paths", "seed-paths")
336+
self.check_config_path(rendered.project_dict, "log-path", default_value="logs")
337+
self.check_config_path(rendered.project_dict, "target-path", default_value="target")
332338

333339
try:
334340
ProjectContract.validate(rendered.project_dict)

core/dbt/deprecations.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ class ExposureNameDeprecation(DBTDeprecation):
8181
_event = "ExposureNameDeprecation"
8282

8383

84+
class ConfigLogPathDeprecation(DBTDeprecation):
85+
_name = "project-config-log-path"
86+
_event = "ConfigLogPathDeprecation"
87+
88+
89+
class ConfigTargetPathDeprecation(DBTDeprecation):
90+
_name = "project-config-target-path"
91+
_event = "ConfigTargetPathDeprecation"
92+
93+
8494
def renamed_env_var(old_name: str, new_name: str):
8595
class EnvironmentVariableRenamed(DBTDeprecation):
8696
_name = f"environment-variable-renamed:{old_name}"
@@ -116,6 +126,8 @@ def warn(name, *args, **kwargs):
116126
ConfigDataPathDeprecation(),
117127
MetricAttributesRenamed(),
118128
ExposureNameDeprecation(),
129+
ConfigLogPathDeprecation(),
130+
ConfigTargetPathDeprecation(),
119131
]
120132

121133
deprecations: Dict[str, DBTDeprecation] = {d.name: d for d in deprecations_list}

core/dbt/events/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ logger = AdapterLogger("<database name>")
5050

5151
## Compiling types.proto
5252

53-
After adding a new message in types.proto, in the core/dbt/events directory: ```protoc --python_betterproto_out . types.proto```
53+
After adding a new message in types.proto:
54+
```
55+
cd core/dbt/events
56+
protoc --python_betterproto_out . types.proto
57+
```

core/dbt/events/proto_types.py

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/dbt/events/types.proto

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ message ConfigDataPathDeprecationMsg {
305305
ConfigDataPathDeprecation data = 2;
306306
}
307307

308-
//D005
308+
// D005
309309
message AdapterDeprecationWarning {
310310
string old_name = 1;
311311
string new_name = 2;
@@ -316,7 +316,7 @@ message AdapterDeprecationWarningMsg {
316316
AdapterDeprecationWarning data = 2;
317317
}
318318

319-
//D006
319+
// D006
320320
message MetricAttributesRenamed {
321321
string metric_name = 1;
322322
}
@@ -326,7 +326,7 @@ message MetricAttributesRenamedMsg {
326326
MetricAttributesRenamed data = 2;
327327
}
328328

329-
//D007
329+
// D007
330330
message ExposureNameDeprecation {
331331
string exposure = 1;
332332
}
@@ -336,7 +336,7 @@ message ExposureNameDeprecationMsg {
336336
ExposureNameDeprecation data = 2;
337337
}
338338

339-
//D008
339+
// D008
340340
message InternalDeprecation {
341341
string name = 1;
342342
string reason = 2;
@@ -349,7 +349,7 @@ message InternalDeprecationMsg {
349349
InternalDeprecation data = 2;
350350
}
351351

352-
//D009
352+
// D009
353353
message EnvironmentVariableRenamed {
354354
string old_name = 1;
355355
string new_name = 2;
@@ -360,6 +360,26 @@ message EnvironmentVariableRenamedMsg {
360360
EnvironmentVariableRenamed data = 2;
361361
}
362362

363+
// D010
364+
message ConfigLogPathDeprecation {
365+
string deprecated_path = 1;
366+
}
367+
368+
message ConfigLogPathDeprecationMsg {
369+
EventInfo info = 1;
370+
ConfigLogPathDeprecation data = 2;
371+
}
372+
373+
// D011
374+
message ConfigTargetPathDeprecation {
375+
string deprecated_path = 1;
376+
}
377+
378+
message ConfigTargetPathDeprecationMsg {
379+
EventInfo info = 1;
380+
ConfigTargetPathDeprecation data = 2;
381+
}
382+
363383
// E - DB Adapter
364384

365385
// E001

core/dbt/events/types.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,42 @@ def message(self):
408408
return line_wrap_message(warning_tag(f"Deprecated functionality\n\n{description}"))
409409

410410

411+
@dataclass
412+
class ConfigLogPathDeprecation(WarnLevel, pt.ConfigSourcePathDeprecation): # noqa
413+
def code(self):
414+
return "D010"
415+
416+
def message(self):
417+
output = "logs"
418+
cli_flag = "--log-path"
419+
env_var = "DBT_LOG_PATH"
420+
description = (
421+
f"The `{self.deprecated_path}` config in `dbt_project.yml` has been deprecated, "
422+
f"and will no longer be supported in a future version of dbt-core. "
423+
f"If you wish to write dbt {output} to a custom directory, please use "
424+
f"the {cli_flag} CLI flag or {env_var} env var instead."
425+
)
426+
return line_wrap_message(warning_tag(f"Deprecated functionality\n\n{description}"))
427+
428+
429+
@dataclass
430+
class ConfigTargetPathDeprecation(WarnLevel, pt.ConfigSourcePathDeprecation): # noqa
431+
def code(self):
432+
return "D011"
433+
434+
def message(self):
435+
output = "artifacts"
436+
cli_flag = "--target-path"
437+
env_var = "DBT_TARGET_PATH"
438+
description = (
439+
f"The `{self.deprecated_path}` config in `dbt_project.yml` has been deprecated, "
440+
f"and will no longer be supported in a future version of dbt-core. "
441+
f"If you wish to write dbt {output} to a custom directory, please use "
442+
f"the {cli_flag} CLI flag or {env_var} env var instead."
443+
)
444+
return line_wrap_message(warning_tag(f"Deprecated functionality\n\n{description}"))
445+
446+
411447
# =======================================================
412448
# E - DB Adapter
413449
# =======================================================

core/dbt/include/starter_project/dbt_project.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ seed-paths: ["seeds"]
1919
macro-paths: ["macros"]
2020
snapshot-paths: ["snapshots"]
2121

22-
target-path: "target" # directory which will store compiled SQL files
2322
clean-targets: # directories to be removed by `dbt clean`
2423
- "target"
2524
- "dbt_packages"

core/dbt/tests/fixtures/project.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,10 @@ def project_config_update():
177177
# Combines the project_config_update dictionary with project_config defaults to
178178
# produce a project_yml config and write it out as dbt_project.yml
179179
@pytest.fixture(scope="class")
180-
def dbt_project_yml(project_root, project_config_update, logs_dir):
180+
def dbt_project_yml(project_root, project_config_update):
181181
project_config = {
182182
"name": "test",
183183
"profile": "test",
184-
"log-path": logs_dir,
185184
}
186185
if project_config_update:
187186
if isinstance(project_config_update, dict):
@@ -355,7 +354,10 @@ def project_files(project_root, models, macros, snapshots, properties, seeds, te
355354
# We have a separate logs dir for every test
356355
@pytest.fixture(scope="class")
357356
def logs_dir(request, prefix):
358-
return os.path.join(request.config.rootdir, "logs", prefix)
357+
dbt_log_dir = os.path.join(request.config.rootdir, "logs", prefix)
358+
os.environ["DBT_LOG_PATH"] = str(dbt_log_dir)
359+
yield dbt_log_dir
360+
del os.environ["DBT_LOG_PATH"]
359361

360362

361363
# This fixture is for customizing tests that need overrides in adapter
@@ -379,7 +381,6 @@ def __init__(
379381
test_data_dir,
380382
test_schema,
381383
database,
382-
logs_dir,
383384
test_config,
384385
):
385386
self.project_root = project_root
@@ -390,7 +391,6 @@ def __init__(
390391
self.test_data_dir = test_data_dir
391392
self.test_schema = test_schema
392393
self.database = database
393-
self.logs_dir = logs_dir
394394
self.test_config = test_config
395395
self.created_schemas = []
396396

@@ -498,7 +498,6 @@ def project(
498498
test_data_dir=test_data_dir,
499499
test_schema=unique_schema,
500500
database=adapter.config.credentials.database,
501-
logs_dir=logs_dir,
502501
test_config=test_config,
503502
)
504503
project.drop_test_schema()

0 commit comments

Comments
 (0)