Giving absolute source paths results in dbt clobbering files
See original GitHub issueDescribe 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:
- Created 3 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
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
I was about to open a new bug issue:
when I saw this has been closed, by the way I confirm the above.
When running
with model-paths specified as follows:
the models are left untouched, as expected.
When running the command with the same path but specified as absolute, like follows:
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
directories as usual.
Instead, they are not created and the original models are replaced.
To reproduce, initialize a clean project with:
and simply replace models-path with the absolute path of the models directory itself and launch