Skip to content

[BUG] pre-commit hooks don't work when the dbt-project.yml isn't in the repository root directory. #244

@peter-malcolm-bw

Description

@peter-malcolm-bw

I think the pre-commit hooks added in #172 and improved in #183 have an implicit assumption that the dbt-project.yml lives in the repository root directory.

Our repository folder structure looks like this:

.git 
.github/
jaffle-shop
  dbt_project.yml
  models/
     mart/
       schema.yml

Running the pre-commit hook against a project with changes:

pre-commit run --all-files --verbose dbt-autofix-fix
Fix dbt deprecations.....................................................Passed
- hook id: dbt-autofix-fix
- duration: 2.49s

Error: dbt_project.yml not found in /Path/To/JaffleProject/jaffle-shop
Error: dbt_project.yml not found in /Path/To/JaffleProject/jaffle-shop
Error: dbt_project.yml not found in /Path/To/JaffleProject/jaffle-shop
Error: dbt_project.yml not found in /Path/To/JaffleProject/jaffle-shop

Running the cli script with path from the repository root works:

uvx dbt-autofix deprecations --path=jaffle-shop
Refactored /Path/To/JaffleProject/jaffle-shop/models/mart/schema.yml:

I've had a look at pre_commit_hooks/check_deprecations.py and it doesn't look like the root_path is configurable. Could this be exposed as a CLI arg in the pre-commit hook so we can write something like?

# .pre-commit-config.yaml

repos: 

- repo: https://github.com/dbt-labs/dbt-autofix
  rev: v0.16.1
  hooks:
    - id: dbt-autofix-fix
      args: [--project-dir=jaffle-shop]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions