Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove trailing slashes from source paths (#6102) #6179

Merged
merged 4 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
64 changes: 23 additions & 41 deletions core/dbt/config/project.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,34 @@
import os
from copy import deepcopy
from dataclasses import dataclass, field
from itertools import chain
from typing import (
List,
Dict,
Any,
Optional,
TypeVar,
Union,
Mapping,
)
from typing_extensions import Protocol, runtime_checkable
from typing import Any, Dict, List, Mapping, Optional, TypeVar, Union

import os

from dbt.flags import get_flags
from dbt import deprecations
from dbt.clients.system import path_exists, resolve_path_from_base, load_file_contents
from dbt.clients.system import (load_file_contents, path_exists,
resolve_path_from_base)
jmg-duarte marked this conversation as resolved.
Show resolved Hide resolved
from dbt.clients.yaml_helper import load_yaml_text
from dbt.config.selectors import SelectorDict
from dbt.contracts.connection import QueryComment
from dbt.exceptions import (
DbtProjectError,
SemverError,
ProjectContractBrokenError,
ProjectContractError,
DbtRuntimeError,
)
from dbt.contracts.project import PackageConfig
from dbt.contracts.project import Project as ProjectContract
from dbt.contracts.project import ProjectPackageMetadata, SemverString
from dbt.dataclass_schema import ValidationError
from dbt.exceptions import (DbtProjectError, DbtRuntimeError,
ProjectContractBrokenError, ProjectContractError,
SemverError)
jmg-duarte marked this conversation as resolved.
Show resolved Hide resolved
from dbt.flags import get_flags
from dbt.graph import SelectionSpec
from dbt.helper_types import NoValue
from dbt.node_types import NodeType
from dbt.semver import VersionSpecifier, versions_compatible
from dbt.version import get_installed_version
from dbt.utils import MultiDict, md5
from dbt.node_types import NodeType
from dbt.config.selectors import SelectorDict
from dbt.contracts.project import (
Project as ProjectContract,
SemverString,
)
from dbt.contracts.project import PackageConfig, ProjectPackageMetadata
from dbt.dataclass_schema import ValidationError
from .renderer import DbtProjectYamlRenderer, PackageRenderer
from .selectors import (
selector_config_from_data,
selector_data_from_root,
SelectorConfig,
)
from dbt.version import get_installed_version
from typing_extensions import Protocol, runtime_checkable

from .renderer import DbtProjectYamlRenderer, PackageRenderer
from .selectors import (SelectorConfig, selector_config_from_data,
selector_data_from_root)
jmg-duarte marked this conversation as resolved.
Show resolved Hide resolved

INVALID_VERSION_ERROR = """\
This version of dbt is not supported with the '{package}' package.
Expand Down Expand Up @@ -137,11 +120,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