Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-2944] [Bug] Ambiguous reference error for tests when model name is duplicated across packages #8327

Closed
2 tasks done
Tracked by #7979
jtcohen6 opened this issue Aug 6, 2023 · 1 comment · Fixed by #8488
Closed
2 tasks done
Tracked by #7979
Assignees
Labels
bug Something isn't working multi_project semantic Issues related to the semantic layer
Milestone

Comments

@jtcohen6
Copy link
Contributor

jtcohen6 commented Aug 6, 2023

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

When:

  • a model with the same name is defined in multiple projects
  • those projects are installed in the same runtime environment (via packages)
  • at least one of those models has a generic test defined

dbt raises an ambiguous reference error

Expected Behavior

dbt should successfully parse my project, and resolve tests to reference the model in the same project/package where they are defined

Steps To Reproduce

Create a project named my_dbt_project, and another local project under a subdirectory named mypkg/.

Within the root project:

# dbt_project.yml
name: my_dbt_project
profile: default
# dependencies.yml OR packages.yml
packages:
  - local: mypkg
-- models/model_a.sql
select 1 as id
# models/config.yml
models:
  - name: model_a
    columns:
      - name: id
        tests:
          - unique

Within the package mypkg, add the exact same model with the exact same config:

# mypkg/dbt_project.yml
name: mypkg
-- mypkg/models/model_a.sql
select 1 as id
# mypkg/models/config.yml
models:
  - name: model_a
    columns:
      - name: id
        tests:
          - unique

From the root project:

$ dbt deps
14:10:31  Running with dbt=1.6.0
14:10:31  Installing mypkg
14:10:31  Installed from <local @ mypkg>

$ dbt --no-partial-parse parse
14:10:43  Running with dbt=1.6.0
14:10:43  Registered adapter: postgres=1.6.0
14:10:44  Encountered an error:
Compilation Error
  When referencing 'model_a', dbt found nodes in multiple packages: 'model.my_dbt_project.model_a', 'model.mypkg.model_a'
  To fix this, use two-argument 'ref', with the package name first: 'my_dbt_project' or 'mypkg'

Remove the unique tests, then parse again (this time successfully):

$ dbt --no-partial-parse parse
14:11:23  Running with dbt=1.6.0
14:11:24  Registered adapter: postgres=1.6.0
14:11:24  Performance info: /Users/jerco/dev/scratch/testy/target/perf_info.json

Environment

- OS: macOS Ventura 13.4.1
- Python: 3.10.11
- dbt: 1.6.0

Which database adapter are you using with dbt?

any

Additional Context

I believe this is a bug in v1.6, insofar as it falls under the intended scope of:

And was missed by the implementation in:

@jtcohen6 jtcohen6 added the bug Something isn't working label Aug 6, 2023
@jtcohen6 jtcohen6 added this to the v1.6.x milestone Aug 6, 2023
@github-actions github-actions bot changed the title [Bug] Ambiguous reference error for tests when model name is duplicated across packages [CT-2944] [Bug] Ambiguous reference error for tests when model name is duplicated across packages Aug 6, 2023
@jtcohen6
Copy link
Contributor Author

jtcohen6 commented Aug 15, 2023

I'm seeing this bug coming up more frequently, because of a change related to the dbt Core v1.6 ←→ MetricFlow integration. each project/package that defines semantic_models and metrics also needs to define a model named metricflow_time_spine. This leads to multiple installations of metricflow_time_spine (from packages + root project), and if any of those packages defines a test on metricflow_time_spine (e.g.), it raises this error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working multi_project semantic Issues related to the semantic layer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants