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-2472] Allow duplicate model names across packages #7446

Closed
Tracked by #7372
MichelleArk opened this issue Apr 24, 2023 · 0 comments · Fixed by #7374
Closed
Tracked by #7372

[CT-2472] Allow duplicate model names across packages #7446

MichelleArk opened this issue Apr 24, 2023 · 0 comments · Fixed by #7374
Assignees

Comments

@MichelleArk
Copy link
Contributor

Current State
During manifest parsing, dbt raises a compilation error if dbt detects two (unversioned) models with the same name:

Compilation Error
  dbt found two models with the name "model_a".
  
  Since these resources have the same name, dbt will be unable to find the correct resource
  when looking for ref("model_a").
  
  To fix this, change the name of one of these resources:
  - model.project_b.model_a (models/model_a.sql)
  - model.project_a.model_a (models/model_a.sql)

This is so that refs originating from any project (project_a, project_b, root_project) don’t have an ambiguous resolution for ref('model_a')

Proposal
To support installing multiple packages as projects, we should relax this uniqueness constraint and allow duplicate model (or other ref-able resource) names across packages. Model name uniqueness should still be enforced within a single project.

ref resolution
Assuming a model named model_a is defined in project_a, and project_b, both of which are installed in a root project:

  1. model in project_a has a ref('model_a') → ref resolves to model.project_a.model_a
  2. model in project_b has a ref('model_a') → ref resolves to model.project_b.model_a
  3. model in root (running) project has a ref('model_a')
    • if it defines its own model_a node → model.root_project.model_a
    • otherwise: raise an error indicating an ambiguous ref

The first two scenarios already work! But the third is broken because dbt resolves “model_a” to an arbitrary project.

** Notes **
Bypassing the initial error can lead to a totally legitimate error aiming to prevent clobbering in the database:

Compilation Error
  dbt found two resources with the database representation ""dbt"."test_arky"."model_a"".
  dbt cannot create two resources with identical database representations. To fix this,
  change the configuration of one of these resources:
  - model.project_b.model_a (models/model_a.sql)
  - model.project_a.model_a (models/model_a.sql)

In this case, the root project should define configurations in its dbt_project.yml to ensure no alias clobbering occurs. For example:

models:
  project_a:
    +schema: project_a
  project_b:
    +schema: project_b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant