Skip to content

Commit

Permalink
Remove trailing slashes from source paths (#6102) (#6179)
Browse files Browse the repository at this point in the history
* Remove trailing slashes from source paths (#6102)

* Run changie

* Handle mypy complaints

* Revert format
  • Loading branch information
jmg-duarte authored Feb 21, 2023
1 parent 05ecfbc commit 7667784
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20221030-102114.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: Remove trailing slashes from source paths (#6102)
time: 2022-10-30T10:21:14.660221Z
custom:
Author: jmg-duarte
Issue: "6102"
PR: "6179"
9 changes: 4 additions & 5 deletions core/dbt/config/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ def _all_source_paths(
analysis_paths: List[str],
macro_paths: List[str],
) -> List[str]:
# We need to turn a list of lists into just a list, then convert to a set to
# get only unique elements, then back to a list
return list(
set(list(chain(model_paths, seed_paths, snapshot_paths, analysis_paths, macro_paths)))
)
paths = chain(model_paths, seed_paths, snapshot_paths, analysis_paths, macro_paths)
# Strip trailing slashes since the path is the same even though the name is not
stripped_paths = map(lambda s: s.rstrip("/"), paths)
return list(set(stripped_paths))


T = TypeVar("T")
Expand Down
24 changes: 24 additions & 0 deletions tests/functional/configs/test_dupe_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,27 @@ def test_config_with_dupe_paths(self, project, dbt_project_yml):
assert len(results) == 1
results = run_dbt(["run"])
assert len(results) == 1


class TestDupeStrippedProjectPaths:
@pytest.fixture(scope="class")
def models(self):
return {
"my_model.sql": my_model_sql,
"seed.csv": seed_csv,
"somedoc.md": somedoc_md,
"schema.yml": schema_yml,
}

@pytest.fixture(scope="class")
def project_config_update(self):
return {
"model-paths": ["models/"],
"seed-paths": ["models"],
}

def test_config_with_dupe_paths(self, project, dbt_project_yml):
results = run_dbt(["seed"])
assert len(results) == 1
results = run_dbt(["run"])
assert len(results) == 1

0 comments on commit 7667784

Please sign in to comment.