Skip to content

Commit

Permalink
bugfix: Deps hangs when using relative paths via --project-dir (#7628
Browse files Browse the repository at this point in the history
…) (#7643)

(cherry picked from commit dcb5acd)

Co-authored-by: Ian Knox <[email protected]>
Co-authored-by: leahwicz <[email protected]>
  • Loading branch information
3 people authored May 24, 2023
1 parent b06a8eb commit 8887c0c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230515-123654.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: 'Fix: Relative project paths weren''t working with deps'
time: 2023-05-15T12:36:54.807413-05:00
custom:
Author: iknox-fa
Issue: "7491"
2 changes: 1 addition & 1 deletion core/dbt/clients/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _windows_rmdir_readonly(func: Callable[[str], Any], path: str, exc: Tuple[An

def resolve_path_from_base(path_to_resolve: str, base_path: str) -> str:
"""
If path-to_resolve is a relative path, create an absolute path
If path_to_resolve is a relative path, create an absolute path
with base_path as the base.
If path_to_resolve is an absolute path or a user path (~), just
Expand Down
8 changes: 7 additions & 1 deletion core/dbt/task/deps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Any, Optional

from pathlib import Path
import dbt.utils
import dbt.deprecations
import dbt.exceptions
Expand Down Expand Up @@ -29,6 +29,12 @@

class DepsTask(BaseTask):
def __init__(self, args: Any, project: Project):
# N.B. This is a temporary fix for a bug when using relative paths via
# --project-dir with deps. A larger overhaul of our path handling methods
# is needed to fix this the "right" way.
# See GH-7615
project.project_root = str(Path(project.project_root).resolve())

move_to_nearest_project_dir(project.project_root)
super().__init__(args=args, config=None, project=project)
self.cli_vars = args.vars
Expand Down
30 changes: 10 additions & 20 deletions tests/functional/dependencies/test_local_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import dbt.config
import dbt.exceptions

from dbt.tests.util import (
check_relations_equal,
run_dbt,
)
from dbt.tests.util import check_relations_equal, run_dbt, run_dbt_and_capture

models__dep_source = """
{# If our dependency source didn't exist, this would be an errror #}
Expand Down Expand Up @@ -155,23 +152,16 @@ def test_local_dependency(self, project):
[f"{project.test_schema}.dep_source_model", f"{project.test_schema}.seed"],
)

def test_no_dependency_paths(self, project):
run_dbt(["deps"])
run_dbt(["seed"])

# prove dependency does not exist as model in project
dep_path = os.path.join("models_local", "model_to_import.sql")
results = run_dbt(
["run", "--models", f"+{dep_path}"],
)
assert len(results) == 0

# prove model can run when importing that dependency
local_path = Path("models") / "my_model.sql"
results = run_dbt(
["run", "--models", f"+{local_path}"],
)
assert len(results) == 2
class TestSimpleDependencyRelativePath(BaseDependencyTest):
def test_local_dependency_relative_path(self, project):
last_dir = Path(project.project_root).name
os.chdir("../")
_, stdout = run_dbt_and_capture(["deps", "--project-dir", last_dir])
assert (
"Installed from <local @ local_dependency>" in stdout
), "Test output didn't contain expected string"
os.chdir(project.project_root)


class TestMissingDependency(object):
Expand Down

0 comments on commit 8887c0c

Please sign in to comment.