dbt-labs / dbt-core

dbt enables data analysts and engineers to transform their data using the same practices that software engineers use to build applications.
https://getdbt.com
Apache License 2.0
9.66k stars 1.6k forks source link

[Bug] "dbt compile" is giving Compilation Error #10757

Open techwithshadab opened 20 hours ago

techwithshadab commented 20 hours ago

Is this a new bug in dbt-core?

Current Behavior

dbt compile is giving Compilation Error

dbt found two macros named "group_by" in the project "media_datalake". To fix this error, rename or remove one of the following macros:

Expected Behavior

dbt compile should run successfully without giving the above error

Steps To Reproduce

Package Version dbt-core==1.8.6 dbt-snowflake==1.8.3

Packages YML file

packages:
  - package: dbt-labs/dbt_utils
    version: 1.3.0
  - package: dbt-labs/codegen
    version: 0.12.1
  - package: dbt-labs/audit_helper
    version: 0.12.0
  - package: dbt-labs/dbt_project_evaluator
    version: 0.13.2
  - package: dbt-labs/dbt_external_tables
    version: 0.9.0
  - package: calogica/dbt_expectations
    version: 0.10.3

Relevant log output

No response

Environment

- OS: MacOS Sonoma 14.6.1
- Python:3.9.6

Which database adapter are you using with dbt?

snowflake

Additional Context

No response

giuliosmall commented 5 hours ago

@techwithshadab The error you’re encountering is due to a naming conflict between the group_by macros defined in both the dbt_expectations and dbt_utils packages. When two macros share the same name in your project, dbt doesn’t know which one to use, leading to a compilation error.

dbeatty10 commented 3 hours ago

@techwithshadab thanks for opening this issue!

@giuliosmall good point about the potential root cause. But in this case, I'd expect for this to work just fine since the groupby macro is namespaced to each of the source packages.

For example, this worked for me:

dbt clean
dbt deps
dbt compile -s my_model

Here's the output I got:

$ dbt compile -s my_model
12:28:02  Running with dbt=1.8.6
12:28:04  Registered adapter: snowflake=1.8.3
12:28:04  Found 49 models, 1 seed, 29 data tests, 1003 macros
12:28:04  
12:28:06  Concurrency: 10 threads (target='snowflake')
12:28:06  
12:28:06  Compiled node 'my_model' is:
select 1 as id
group by 1
-- group by 1

Here's the file that I used

models/my_model.sql

select 1 as id
{{ dbt_utils.group_by(1) }}

@techwithshadab Could you share a simple model file that gives this error for you and also share the commands you used?

Could you also share your dbt_project.yml file? I'm wondering if you are overriding the macro-paths config or setting the dispatch, etc.