dbt-core
dbt-core copied to clipboard
Fix for dbt compile overwriting source files
Resolves #10886
Problem
Running dbt compile
can overwrite source files with the newly compiled sql
Solution
Update path building to avoid issues with absolute paths.
The issue appears on this line: https://github.com/dbt-labs/dbt-core/blob/a0674db8400673d7dd4ebf7597dd82b3349337ce/core/dbt/contracts/graph/nodes.py#L267
Consider the case where path
is an absolute path.
For example, running this will give the absolute path as the return value, instead of the expected relative path that will be used as the output target file.
>>> os.path.join("target_path", "subdirectory", "package_name", "/absolute/path/project/models/my_model.sql")
'/absolute/path/project/models/my_model.sql'
Following the change in this PR, we can expect this as the result:
>>> os.path.join("target_path", "subdirectory", "package_name", "models/my_model.sql")
'target_path/subdirectory/package_name/models/my_model.sql'
Checklist
- [x] I have read the contributing guide and understand what's expected of me.
- [x] I have run this code in development, and it appears to resolve the stated issue.
- [x] This PR includes tests, or tests are not required or relevant for this PR.
- [x] This PR has no interface changes (e.g., macros, CLI, logs, JSON artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX.
- [x] This PR includes type annotations for new and modified functions.