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

fix(dbt-doc): Allow copying asset when dbt docs command is run outside th… #11219

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 .changes/unreleased/Fixes-20250116-192616.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Allow copying asset when dbt docs command is run outside the dbt project
time: 2025-01-16T19:26:16.160976423Z
custom:
Author: cedric-orange
Issue: "9308"
6 changes: 4 additions & 2 deletions core/dbt/task/docs/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ def run(self) -> CatalogArtifact:
if os.path.exists(to_asset_path):
shutil.rmtree(to_asset_path)

if os.path.exists(asset_path):
shutil.copytree(asset_path, to_asset_path)
from_asset_path = os.path.join(self.config.project_root, asset_path)

if os.path.exists(from_asset_path):
shutil.copytree(from_asset_path, to_asset_path)

if self.manifest is None:
raise DbtInternalError("self.manifest was None in run!")
Expand Down
27 changes: 24 additions & 3 deletions tests/functional/adapter/basic/test_docs_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,30 @@ def test_run_and_generate(self, project, expected_catalog):
verify_catalog(project, expected_catalog, start_time)

# Check that assets have been copied to the target directory for use in the docs html page
assert os.path.exists(os.path.join("", "target", "assets"))
assert os.path.exists(os.path.join("", "target", "assets", "lorem-ipsum.txt"))
assert not os.path.exists(os.path.join("", "target", "non-existent-assets"))
assert os.path.exists(os.path.join(project.project_root, "target", "assets"))
assert os.path.exists(
os.path.join(project.project_root, "target", "assets", "lorem-ipsum.txt")
)
assert not os.path.exists(
os.path.join(project.project_root, "target", "non-existent-assets")
)

# Test generic "docs generate" command
def test_locally_run_and_generate(self, project, expected_catalog):
os.chdir(
project.profiles_dir
) # Change to random directory to test that assets doc generation works with project-dir
start_time = run_and_generate(project)
verify_catalog(project, expected_catalog, start_time)

# Check that assets have been copied to the target directory for use in the docs html page
assert os.path.exists(os.path.join(project.project_root, "target", "assets"))
assert os.path.exists(
os.path.join(project.project_root, "target", "assets", "lorem-ipsum.txt")
)
assert not os.path.exists(
os.path.join(project.project_root, "target", "non-existent-assets")
)


class TestDocsGenerate(BaseDocsGenerate):
Expand Down