diff --git a/.changes/unreleased/Fixes-20241018-150256.yaml b/.changes/unreleased/Fixes-20241018-150256.yaml new file mode 100644 index 00000000000..bf830ea40c0 --- /dev/null +++ b/.changes/unreleased/Fixes-20241018-150256.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Prevent dbt compile from overwriting files that are passed in as absolute paths +time: 2024-10-18T15:02:56.289808-07:00 +custom: + Author: Myles1 + Issue: "10886" diff --git a/core/dbt/contracts/graph/nodes.py b/core/dbt/contracts/graph/nodes.py index 2d9ff77b385..196d902e59c 100644 --- a/core/dbt/contracts/graph/nodes.py +++ b/core/dbt/contracts/graph/nodes.py @@ -251,7 +251,7 @@ def get_target_write_path( # This is called for both the "compiled" subdirectory of "target" and the "run" subdirectory if os.path.basename(self.path) == os.path.basename(self.original_file_path): # One-to-one relationship of nodes to files. - path = self.original_file_path + path = self.path else: # Many-to-one relationship of nodes to files. path = os.path.join(self.original_file_path, self.path) diff --git a/tests/functional/adapter/simple_seed/test_seed.py b/tests/functional/adapter/simple_seed/test_seed.py index 536ed7ad017..18c25713ebf 100644 --- a/tests/functional/adapter/simple_seed/test_seed.py +++ b/tests/functional/adapter/simple_seed/test_seed.py @@ -386,3 +386,27 @@ def test_empty_seeds(self, project): class TestEmptySeed(BaseTestEmptySeed): pass + + +class TestAbsoluteSeedPaths: + """ + This is a regression test for issue #10886. + We're ensuring that dbt will not overwrite files that are passed in as asbolute paths in dbt_project.yml + """ + + @pytest.fixture(scope="class") + def project_config_update(self, project_root): + # Assign an absolute path to seed-paths + return { + "seed-paths": [str(Path(project_root) / "seeds")], + } + + @pytest.fixture(scope="class") + def seeds(self): + return {"my_seed.csv": seed__with_dots_csv} + + def test_absolute_seeds_paths(self, project): + results = run_dbt(["seed"]) + assert len(results) == 1 + # Should not fail due to file being overwritten + results = run_dbt(["seed"])