question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Giving absolute source paths results in dbt clobbering files

See original GitHub issue

Describe the bug

If your dbt_project.yml has absolute paths, dbt will decide that the “build path” for your node is the same as its original file path, and overwrite the source file with the compiled output. That’s awful! We should do literally anything else.

In a similar issue, if you provide a path with .. in it, the compiled path will include those ...

Steps To Reproduce

Imagine you have this dbt_project.yml in /Users/user/my-project:

config-version: 2
name: my-project
version: 1.0

source-paths: ['/Users/user/my-project/models']

This is a reasonable-enough thing to write, although it’s not really what dbt expects you to do.

Now write a model like this to /Users/user/my-project/models/model.sql:

select 1 as id

Now issue a dbt run command. Observe that /Users/user/my-project/models/model.sql now looks like this:

create or replace view dbt.dbt_user.model

  as
    select 1 as id

I think it’s safe to assume that this behavior happens with more than just models.

You can perform similar operations with .. in the path, though the file won’t be overwritten. Instead, the file will be written to a more complicated path formed via os.path.join.

Expected behavior

Almost any other behavior would be acceptable, but the ideal is probably something along the lines of detecting that '/Users/user/my-project/models' is a subdirectory of the project root and rewriting it to be relative.

I’m not sure exactly how this would handle the .. case, maybe just drop those entirely? Or replace them with ‘parent’? We have a good amount of flexibility on that front, though we probably should not error out - I’m pretty confident that people use this behavior to reference models outside their current tree.

System information

Which database are you using dbt with? Any database

The output of dbt --version: 0.17.1, I’m not sure how far this goes back

The operating system you’re using: macos

The output of python --version: 3.8? I am pretty confident this is version agnostic.

Additional context

The bad behavior happens in dbt.contracts.graph.parsed.ParsedNodeDefaults.write_node

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
chloeliucommented, Apr 16, 2021

This same issue happened to us as well. I think it was working for 0.15 but it is no longer the case after 0.17. We were trying to upgrade to 0.19. linux system, python 3.7

0reactions
simonepmcommented, Apr 6, 2022

I was about to open a new bug issue:

[Bug] Models files get replaced when models-path is absolute

when I saw this has been closed, by the way I confirm the above.

When running

dbt run 

with model-paths specified as follows:

model-paths: ["models"]

the models are left untouched, as expected.

When running the command with the same path but specified as absolute, like follows:

model-paths: ["C:\\path\\to\\models"]

The models are applied on the remote database, but the original files are replaced with the their ‘run’ folder compiled version.

Furthermore, the ‘target’ folder is not populated.

The expected behavior is having the models left untouched and the generation taking place in

<project>/target/compiled/<project>/modules
<project>/target/run/<project>/modules

directories as usual.

Instead, they are not created and the original models are replaced.

To reproduce, initialize a clean project with:

dbt init

and simply replace models-path with the absolute path of the models directory itself and launch

dbt run
  • OS: Windows 10
  • Python: 3.7.12
  • dbt: 1.0.4
Read more comments on GitHub >

github_iconTop Results From Across the Web

Giving absolute source paths results in dbt clobbering files
If your dbt_project.yml has absolute paths, dbt will decide that the "build path" for your node is the same as its original file...
Read more >
resource-path - dbt Developer Hub
It represents the nested dictionary keys that provide the path to either a directory of models, or a single model. Example​. info. This...
Read more >
dbt Changelog - pyup.io
Any `.sql` file found in the `test-paths` director(y|ies) will be evaluated as data tests. These tests can be run with: bash dbt test...
Read more >
Debugging with gdb
The purpose of a debugger such as gdb is to allow you to see what is going on “inside” another program while it...
Read more >
Using as - sourceware.org
1 Overview · 1.1 Structure of this Manual · 1.2 The GNU Assembler · 1.3 Object File Formats · 1.4 Command Line ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found