Skip to content

Commit f2efb25

Browse files
committed
Added support to --skip-debug in dbt init
1 parent 31bbdd1 commit f2efb25

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

core/dbt/cli/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ def deps(ctx, **kwargs):
473473
@p.profiles_dir_exists_false
474474
@p.project_dir
475475
@p.skip_profile_setup
476+
@p.skip_debug
476477
@p.vars
477478
@requires.postflight
478479
@requires.preflight

core/dbt/cli/params.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,13 @@ def _create_option_and_track_env_var(
631631
is_flag=True,
632632
)
633633

634+
skip_debug = _create_option_and_track_env_var(
635+
"--skip-debug",
636+
envvar=None,
637+
help="Skip running dbt debug after project initialization.",
638+
is_flag=True,
639+
)
640+
634641
source = _create_option_and_track_env_var(
635642
"--source",
636643
envvar=None,

core/dbt/task/init.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ def run(self):
327327
if not self.args.skip_profile_setup:
328328
profile_name = self.get_profile_name_from_current_project()
329329
self.setup_profile(profile_name)
330-
self._run_debug()
330+
if not self.args.skip_debug:
331+
self._run_debug()
331332
else:
332333
# When dbt init is run outside of an existing project,
333334
# create a new project and set up the user's profile.
@@ -345,7 +346,7 @@ def run(self):
345346
msg="Could not find profile named '{}'".format(user_profile_name)
346347
)
347348
self.create_new_project(project_name, user_profile_name)
348-
debug_success = self._run_debug()
349+
debug_success = self._run_debug() if not self.args.skip_debug else None
349350
else:
350351
profile_name = project_name
351352
# Create the profile after creating the project to avoid leaving a random profile
@@ -355,7 +356,7 @@ def run(self):
355356
# Ask for adapter only if skip_profile_setup flag is not provided
356357
if not self.args.skip_profile_setup:
357358
self.setup_profile(profile_name)
358-
debug_success = self._run_debug()
359+
debug_success = self._run_debug() if not self.args.skip_debug else None
359360
else:
360361
debug_success = None
361362

core/hatch.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ test = [
123123
"pre-commit run mypy-check --hook-stage manual --all-files",
124124
]
125125

126-
ft = "python -m pytest -x -nauto ../tests/functional/init/test_init.py"
127-
128126
# Database setup
129127
setup-db = [
130128
"docker compose up -d database",

tests/functional/init/test_init.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,34 @@ def test_debug_skipped_with_skip_profile_setup(
916916
mock_run_debug.assert_not_called()
917917

918918

919+
class TestInitSkipDebugFlag(TestInitInsideOfProjectBase):
920+
@mock.patch("dbt.task.init.InitTask._run_debug")
921+
@mock.patch("dbt.task.init._get_adapter_plugin_names")
922+
@mock.patch("click.confirm")
923+
@mock.patch("click.prompt")
924+
def test_debug_skipped_with_skip_debug_flag(
925+
self, mock_prompt, mock_confirm, mock_get_adapter, mock_run_debug, project
926+
):
927+
"""Verify _run_debug is NOT called when --skip-debug is used."""
928+
manager = Mock()
929+
manager.attach_mock(mock_prompt, "prompt")
930+
manager.attach_mock(mock_confirm, "confirm")
931+
manager.confirm.side_effect = ["y"]
932+
manager.prompt.side_effect = [
933+
1,
934+
"localhost",
935+
5432,
936+
"test_user",
937+
"test_password",
938+
"test_db",
939+
"test_schema",
940+
4,
941+
]
942+
mock_get_adapter.return_value = [project.adapter.type()]
943+
run_dbt(["init", "--skip-debug"])
944+
mock_run_debug.assert_not_called()
945+
946+
919947
class TestInitDebugFailureDoesNotFailInit(TestInitInsideOfProjectBase):
920948
@mock.patch("dbt.task.init._get_adapter_plugin_names")
921949
@mock.patch("click.confirm")

0 commit comments

Comments
 (0)