Skip to content
Merged
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
19 changes: 11 additions & 8 deletions dbt_loom/clients/snowflake_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
from pydantic import BaseModel


def _load_downloaded_manifest(download_path: Path) -> Dict:
"""Read a plain or gzip-compressed manifest downloaded from a stage."""
content = download_path.read_bytes()

if is_gzipped(content):
content = gzip.decompress(content)

return json.loads(content)


class SnowflakeReferenceConfig(BaseModel):
"""Configuration for an reference stored in Snowflake Stage"""

Expand Down Expand Up @@ -72,11 +82,4 @@ def load_manifest(self) -> Dict:

download_path = Path(tmp_dir) / file_name

with download_path.open("r") as f:
content = f.read()

if is_gzipped(content.encode()):
with gzip.GzipFile(content) as gzip_file:
content = gzip_file.read().decode("utf-8")

return json.loads(content)
return _load_downloaded_manifest(download_path)
20 changes: 20 additions & 0 deletions tests/test_snowflake_stage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import gzip
import json

from dbt_loom.clients.snowflake_stage import _load_downloaded_manifest


def test_load_downloaded_manifest_reads_plain_json(tmp_path):
manifest = {"metadata": {"dbt_version": "1.12.2"}}
download_path = tmp_path / "manifest.json"
download_path.write_text(json.dumps(manifest))

assert _load_downloaded_manifest(download_path) == manifest


def test_load_downloaded_manifest_reads_gzip_json(tmp_path):
manifest = {"metadata": {"dbt_version": "1.12.2"}}
download_path = tmp_path / "manifest.json.gz"
download_path.write_bytes(gzip.compress(json.dumps(manifest).encode("utf-8")))

assert _load_downloaded_manifest(download_path) == manifest
Loading