From 78bb854d0a1502ff3d728d7d37fae11147bdf762 Mon Sep 17 00:00:00 2001 From: Kshitij Aranke Date: Tue, 5 Sep 2023 12:41:09 +0100 Subject: [PATCH] Copy dir if symlink fails (#7447) (#8548) Co-authored-by: Anju --- .changes/unreleased/Fixes-20230424-210734.yaml | 6 ++++++ core/dbt/deps/local.py | 8 ++------ tests/unit/test_deps.py | 17 ++++++++++++++++- 3 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 .changes/unreleased/Fixes-20230424-210734.yaml diff --git a/.changes/unreleased/Fixes-20230424-210734.yaml b/.changes/unreleased/Fixes-20230424-210734.yaml new file mode 100644 index 00000000000..3f70881eb90 --- /dev/null +++ b/.changes/unreleased/Fixes-20230424-210734.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Copy dir during `dbt deps` if symlink fails +time: 2023-04-24T21:07:34.336797+05:30 +custom: + Author: anjutiwari + Issue: "7428 8223" diff --git a/core/dbt/deps/local.py b/core/dbt/deps/local.py index 93e2a3cc323..18c9af01de3 100644 --- a/core/dbt/deps/local.py +++ b/core/dbt/deps/local.py @@ -51,19 +51,15 @@ def install(self, project, renderer): src_path = self.resolve_path(project) dest_path = self.get_installation_path(project, renderer) - can_create_symlink = system.supports_symlinks() - if system.path_exists(dest_path): if not system.path_is_symlink(dest_path): system.rmdir(dest_path) else: system.remove_file(dest_path) - - if can_create_symlink: + try: fire_event(DepsCreatingLocalSymlink()) system.make_symlink(src_path, dest_path) - - else: + except OSError: fire_event(DepsSymlinkNotAvailable()) shutil.copytree(src_path, dest_path) diff --git a/tests/unit/test_deps.py b/tests/unit/test_deps.py index 5728cb703b6..39a799e638e 100644 --- a/tests/unit/test_deps.py +++ b/tests/unit/test_deps.py @@ -6,7 +6,7 @@ import dbt.deps import dbt.exceptions from dbt.deps.git import GitUnpinnedPackage -from dbt.deps.local import LocalUnpinnedPackage +from dbt.deps.local import LocalUnpinnedPackage, LocalPinnedPackage from dbt.deps.tarball import TarballUnpinnedPackage from dbt.deps.registry import RegistryUnpinnedPackage from dbt.clients.registry import is_compatible_version @@ -92,6 +92,21 @@ def test_init(self): self.assertEqual(a_pinned.source_type(), "git") self.assertIs(a_pinned.warn_unpinned, True) + @mock.patch("shutil.copytree") + @mock.patch("dbt.deps.local.system.make_symlink") + @mock.patch("dbt.deps.local.LocalPinnedPackage.get_installation_path") + @mock.patch("dbt.deps.local.LocalPinnedPackage.resolve_path") + def test_deps_install( + self, mock_resolve_path, mock_get_installation_path, mock_symlink, mock_shutil + ): + mock_resolve_path.return_value = "/tmp/source" + mock_get_installation_path.return_value = "/tmp/dest" + mock_symlink.side_effect = OSError("Install deps symlink error") + + LocalPinnedPackage("local").install("dummy", "dummy") + self.assertEqual(mock_shutil.call_count, 1) + mock_shutil.assert_called_once_with("/tmp/source", "/tmp/dest") + def test_invalid(self): with self.assertRaises(ValidationError): GitPackage.validate(