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

[CT-3509] [Bug] assets not being copied to target directory with docs generate --project-dir #9308

Open
2 tasks done
hvignolo87 opened this issue Dec 20, 2023 · 5 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@hvignolo87
Copy link

hvignolo87 commented Dec 20, 2023

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

Having an assets-path defined in the dbt_project.yml file:

...

model-paths: ["models"]
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]
target-path: "target"
docs-paths: ["docs"]
asset-paths: ["assets"]

...

The directory assets is not being copied to target/assets when running dbt docs generate, as mentioned in the docs. Then, any attempt to load an image from that directory fails. It works fine with external links and when manually copying assets to target/assets.

Expected Behavior

The assets directory is copied to target/assets and the images shown in the documentation

Steps To Reproduce

  1. Create a new dummy dbt project with dbt init
  2. Complete credentials in profiles.yml
  3. Add asset-paths: ["assets"] to the dbt_project.yml file, and create the directory
  4. Place any image in the assets directory
  5. Create a models/properties.yml file for the example model, and include a description like this one
  6. Run dbt docs generate
  7. Run dbt docs serve --port 8080 --browser
  8. Verify that no image is shown in your model's description

Relevant log output

N/A

Environment

- OS: macOS Sonoma 14.2
- Python: 3.10.12
- dbt: 1.5.6

Which database adapter are you using with dbt?

redshift

Additional Context

I'm running dbt in a virtual environment managed with poetry 1.6.1

@hvignolo87 hvignolo87 added bug Something isn't working triage labels Dec 20, 2023
@github-actions github-actions bot changed the title [Bug] assets not being copied to targets directory [CT-3509] [Bug] assets not being copied to targets directory Dec 20, 2023
@dbeatty10
Copy link
Contributor

Thanks for reaching out and providing such a nice set of instructions @hvignolo87 🥇

I tried reproducing the issue you reported using dbt-postgres==1.5.6, and everything worked as described in the docs.

I wonder if something is accidentally misspelled or misconfigured in your project that can explain what is going on?

Could you try out the example below and see if it works for you or not?

Example that worked for me

Project files

Here's my exact set of files:

dbt_project.yml

name: "my_project"
version: "1.0.0"
config-version: 2
profile: "postgres"

asset-paths: ["assets"]

models/customers.sql

{{ config(materialized="table") }}

select 1 as customer_id

models/properties.yml

version: 2

models:
  - name: customers
    description: "![dbt Logo](assets/dbt-logo.svg)"

    columns:
      - name: customer_id
        description: Primary key

Commands

mkdir -p assets
curl -o assets/dbt-logo.svg https://docs.getdbt.com/img/dbt-logo.svg
dbt docs generate
ls -al target/assets
dbt docs serve --port 8080 --browser

Output

(postgres_1.5) $ mkdir -p assets                    

(postgres_1.5) $ curl -o assets/dbt-logo.svg https://docs.getdbt.com/img/dbt-logo.svg

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3899  100  3899    0     0  12146      0 --:--:-- --:--:-- --:--:-- 12417
(postgres_1.5) $ dbt docs generate

02:01:57  Running with dbt=1.5.6
02:01:57  Registered adapter: postgres=1.5.6
02:01:57  Found 1 model, 0 tests, 0 snapshots, 0 analyses, 307 macros, 0 operations, 0 seed files, 0 sources, 0 exposures, 0 metrics, 0 groups
02:01:57  
02:01:57  Concurrency: 5 threads (target='blue')
02:01:57  
02:01:57  Building catalog
02:01:57  Catalog written to /dbt-core-9308/target/catalog.json
(postgres_1.5) $ ls -al target/assets

total 8
drwxr-xr-x   3 dbeatty  staff    96 Dec 20 18:39 .
drwxr-xr-x  13 dbeatty  staff   416 Dec 20 19:01 ..
-rw-r--r--   1 dbeatty  staff  3899 Dec 20 19:01 dbt-logo.svg
image

@hvignolo87
Copy link
Author

Hi @dbeatty10! Thank you very much for your quick answer! 😅

I'm not able to reproduce your example, still not working for me.

Here's a MRE of what I have locally.
dbt_test.zip

Please fill in your credentials in profiles.yml, and then run:

poetry run dbt docs generate --project-dir test --profiles-dir test

Then please go to the targets folder and see if the assets directory is there.

Here's a video of what I'm doing:
https://drive.google.com/file/d/1YLyHTxzjjByXJEjbgEQBy1DDquIN5qMP/view?usp=drive_link

@dbeatty10
Copy link
Contributor

Thanks for your source code for a MRE along with a video 🤩

That helps get to the bottom of things.

Let's suppose I have a project located at /some_path/test/ and that is also the current working directory.

✅ Then any of the following does successfully add the /some_path/test/target/assets/ directory:

dbt docs generate
dbt docs generate --project-dir .
dbt docs generate --project-dir /some_path/test/

❌ But this does not add the /some_path/test/target/assets/ directory:

dbt docs generate --project-dir /some_path/test/

So ultimately it's the --project-dir flag that is not working with the docs generate sub-command when the project directory is not the current working directory.

This looks similar to #8385 to me, and it might have a similar solution.

@dbeatty10
Copy link
Contributor

I've confirmed that this is an issue in 1.7 (currently the latest) as well as dbt-core 1.5 (as originally reported).

Acceptance criteria

  • Using the example project here, dbt docs generate --project-dir some_path will generate some_path/target/assets/ even when some_path is not the current working directory
  • There is a functional test (potentially similar to #8388) that tests --project-dir for docs generate

@dbeatty10 dbeatty10 removed the triage label Dec 21, 2023
@dbeatty10 dbeatty10 changed the title [CT-3509] [Bug] assets not being copied to targets directory [CT-3509] [Bug] assets not being copied to target directory with docs generate --project-dir Dec 21, 2023
@hvignolo87
Copy link
Author

hvignolo87 commented Dec 21, 2023

Let's suppose I have a project located at /some_path/test/ and that is also the current working directory.

✅ Then any of the following does successfully add the /some_path/test/target/assets/ directory:

dbt docs generate
dbt docs generate --project-dir .
dbt docs generate --project-dir /some_path/test/

This worked for me too 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants