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-2510] [Bug] Raise an error if non-versioned model is defined with same name as existing versioned model #7487

Closed
Tracked by #7372
jtcohen6 opened this issue May 2, 2023 · 6 comments · Fixed by #7577
Assignees
Labels
bug Something isn't working jira partial_parsing
Milestone

Comments

@jtcohen6
Copy link
Contributor

jtcohen6 commented May 2, 2023

Set up:

-- models/my_model_v1.sql
select 1 as id
# models/whatever.yml
models:
  - name: my_model
    versions:
      - v: 1
$ dbt parse
12:48:12  Running with dbt=1.5.0
12:48:14  Performance info: target/perf_info.json

Now:

  • create models/my_model.sql (no version suffix)
  • do not add any new versions to the versions block in the yaml file

Re-parse with partial parsing, and everything looks fine:

$ dbt parse
12:48:29  Running with dbt=1.5.0
12:48:30  Performance info: target/perf_info.json

And now without partial parsing, I see an error (good! I should!):

$ dbt --no-partial-parse parse
12:48:43  Running with dbt=1.5.0
12:48:46  Encountered an error:
Compilation Error
  dbt found two models with the name "my_model".

  Since these resources have the same name, dbt will be unable to find the correct resource
  when looking for ref("my_model").

  To fix this, change the name of one of these resources:
  - model.my_dbt_project.my_model (models/my_model.sql)
  - model.my_dbt_project.my_model.v1 (models/my_model_v1.sql)
@jtcohen6 jtcohen6 added the bug Something isn't working label May 2, 2023
@github-actions github-actions bot changed the title [Bug] [PPRaise clearer error message if a model is defined both with + without version [CT-2509] [Bug] [PPRaise clearer error message if a model is defined both with + without version May 2, 2023
@jtcohen6 jtcohen6 changed the title [CT-2509] [Bug] [PPRaise clearer error message if a model is defined both with + without version [Bug] [Partial Parsing] Error if non-versioned model is defined with same name as existing versioned model May 2, 2023
@jtcohen6 jtcohen6 added this to the v1.5.x milestone May 2, 2023
@jtcohen6 jtcohen6 added the jira label May 2, 2023
@github-actions github-actions bot changed the title [Bug] [Partial Parsing] Error if non-versioned model is defined with same name as existing versioned model [CT-2510] [Bug] [Partial Parsing] Error if non-versioned model is defined with same name as existing versioned model May 2, 2023
@gshank gshank self-assigned this May 4, 2023
@gshank
Copy link
Contributor

gshank commented May 9, 2023

This is not a partial parsing bug per se. I've created a test case which does not fail appropriately even with full parsing.

@gshank
Copy link
Contributor

gshank commented May 9, 2023

I haven't been able to recreate the compilation error. Whether I create the non-versioned model first or second, it never complains.

@dbeatty10
Copy link
Contributor

I tried the same set of steps as outlined and was not able to produce the compilation error.

@jtcohen6 jtcohen6 changed the title [CT-2510] [Bug] [Partial Parsing] Error if non-versioned model is defined with same name as existing versioned model [CT-2510] [Bug] [Partial Parsing] Raise an error if non-versioned model is defined with same name as existing versioned model May 9, 2023
@dbeatty10
Copy link
Contributor

dbeatty10 commented May 9, 2023

I can reproduce this now. I accidentally didn't create and save models/my_model.sql 😅

Here's my key files at the end:

models/_models.yml

models:
  - name: my_model
    versions:
      - v: 1

models/my_model_v1.sql

select 1 as id

models/my_model.sql

select 0 as id

@gshank
Copy link
Contributor

gshank commented May 9, 2023

Commit 0de046d yesterday removed the code that was causing the error in the example to be thrown.

@gshank
Copy link
Contributor

gshank commented May 9, 2023

The error was thrown in the no-partial-parse case and not in the partial parse case because the order of the nodes encountered was different and the code was checking is_versioned for the previously encountered node.

@gshank gshank changed the title [CT-2510] [Bug] [Partial Parsing] Raise an error if non-versioned model is defined with same name as existing versioned model [CT-2510] [Bug] Raise an error if non-versioned model is defined with same name as existing versioned model May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working jira partial_parsing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants