Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions dbt_loom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ def identify_node_subgraph(manifest) -> Dict[str, ManifestNode]:
if not node:
continue

if (
node.get("resource_type") == NodeType.Model.value
and node.get("config", {}).get("materialized") == "ephemeral"
):
continue

if node.get("access") is None:
node["access"] = node.get("config", {}).get("access", "protected")

Expand Down
4 changes: 2 additions & 2 deletions dbt_loom/manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def load_from_local_filesystem(config: FileReferenceConfig) -> Dict:
if not file_path.exists():
raise LoomConfigurationError(f"The path `{file_path}` does not exist.")

file = open(file_path)
content = file.read()
with open(file_path, encoding="utf-8") as file:
content = file.read()
if is_gzipped(content.encode()):
with gzip.GzipFile(content) as gz_file:
return json.load(gz_file)
Expand Down
12 changes: 11 additions & 1 deletion tests/test_manifest_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,24 @@ def test_load_from_local_filesystem_pass(example_file):
path, example_content = example_file

file_config = FileReferenceConfig(
path=urlparse("file://" + str(Path(path).absolute()))
path=urlparse(Path(path).absolute().as_uri())
)

output = ManifestLoader.load_from_local_filesystem(file_config)

assert output == example_content


def test_load_from_local_filesystem_utf8(tmp_path):
"""Confirm local manifests with UTF-8 characters load on Windows."""
path = tmp_path / "manifest.json"
expected = {"description": "café"}
path.write_text(json.dumps(expected), encoding="utf-8")
file_config = FileReferenceConfig(path=str(path)) # type: ignore

assert ManifestLoader.load_from_local_filesystem(file_config) == expected


def test_load_from_local_filesystem_local_path(example_file):
"""Test that ManifestLoader can load a local JSON file."""

Expand Down
60 changes: 57 additions & 3 deletions tests/test_node_deduplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,29 @@ def _make_manifest(project_name, nodes):
}


def _make_node(unique_id, package_name, access="protected"):
def _make_node(
unique_id,
package_name,
access="protected",
*,
name=None,
relation_name=None,
materialized=None,
):
"""Helper to create a minimal manifest node dict."""
return {
node = {
"unique_id": unique_id,
"name": unique_id.split(".")[-1],
"name": name or unique_id.split(".")[-1],
"package_name": package_name,
"schema": "core",
"resource_type": "model",
"access": access,
}
if relation_name is not None:
node["relation_name"] = relation_name
if materialized is not None:
node["config"] = {"materialized": materialized}
return node


def _merge_manifests(manifest_pairs):
Expand Down Expand Up @@ -137,3 +150,44 @@ def test_first_transitive_copy_preserved_over_later_copies():
)

assert models[uid].access == "public"


def test_ephemeral_version_is_not_injected_alongside_materialized_version():
"""Ephemeral versions have no relation and can collide with a versioned model."""

model_name = "STG_H_ICOACH_COACHING_SESSION"
v1_uid = f"model.icoach_source.{model_name}.v1"
v3_uid = f"model.icoach_source.{model_name}.v3"

models = _merge_manifests(
[
(
_make_manifest(
"icoach_source",
{
v1_uid: _make_node(
v1_uid,
"icoach_source",
access="public",
name=model_name,
relation_name=(
"DEV_DB.STAGE_SCHEMA.STG_H_ICOACH_COACHING_SESSION"
),
materialized="table",
),
v3_uid: _make_node(
v3_uid,
"icoach_source",
name=model_name,
materialized="ephemeral",
),
},
),
"icoach_source",
),
]
)

assert v1_uid in models
assert v3_uid not in models
assert models[v1_uid].identifier == model_name