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-2436] [Bug] Version 0 makes itself the latest_version #7408

Closed
2 tasks done
dbeatty10 opened this issue Apr 18, 2023 · 0 comments · Fixed by #7415
Closed
2 tasks done

[CT-2436] [Bug] Version 0 makes itself the latest_version #7408

dbeatty10 opened this issue Apr 18, 2023 · 0 comments · Fixed by #7415
Assignees
Labels
bug Something isn't working model_versions
Milestone

Comments

@dbeatty10
Copy link
Contributor

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

https://docs.getdbt.com/docs/collaborate/govern/model-versions#how-to-create-a-new-version-of-a-model

I was expecting that I could do something like this:

models:
  - name: dim_customers
    versions:
      - v: 1
      - v: 0
        defined_in: dim_customers  # keep original file name

And then have a model that generically always selects from the latest_version (without actually needing to specify the version):

models/dim_customers_latest

select * from {{ ref('dim_customers') }}

But the reference doesn't work correctly when starting the versioning at 0. It does work when starting the versioning at 1.

Expected Behavior

See above.

Steps To Reproduce

Not working when starting with v: 0

models/_models.yml

models:
  - name: dim_customers
    versions:
      - v: 1
      - v: 0
        defined_in: dim_customers  # keep original file name

models/dim_customers.sql

{{ config(alias="dim_customers") }}

select 7 as id, 'Argentina' as country_name

models/dim_customers_v1.sql

select 12 as id, 'Bahamas' as country_name

models/dim_customers_latest.sql

select * from {{ ref('dim_customers') }}

Run the models and inspect the latest version:

dbt run
dbt show -s dim_customers_latest
id country_name
7 Argentina

This also doesn't work

Explicitly setting the latest_version doesn't work either:

models:
  - name: dim_customers
    latest_version: 1
    versions:
      - v: 1
      - v: 0
        defined_in: dim_customers  # keep original file name

Working when starting with v: 1

Same project as above, but with the following modifications:

Re-index the version numbers:

models/_models.yml

models:
  - name: dim_customers
    versions:
      - v: 2
      - v: 1
        defined_in: dim_customers  # keep original file name

Rename v1 to v2:

mv models/dim_customers_v1.sql models/dim_customers_v2.sql 

Try it again, and it shows the expected data:

dbt run
dbt show -s dim_customers_latest
id country_name
12 Bahamas

Relevant log output

No response

Environment

- OS:
- Python:
- dbt: 1.5.0rc1

dbt-postgres

Which database adapter are you using with dbt?

No response

Additional Context

When inspecting the manifest, its latest_version values all looked correct. So the underlying difference is probably in the implementation of ref() somehow.

@dbeatty10 dbeatty10 added bug Something isn't working triage labels Apr 18, 2023
@github-actions github-actions bot changed the title [Bug] Version 0 makes itself the latest_version [CT-2436] [Bug] Version 0 makes itself the latest_version Apr 18, 2023
@jtcohen6 jtcohen6 added this to the v1.5.x milestone Apr 19, 2023
@MichelleArk MichelleArk self-assigned this Apr 19, 2023
@MichelleArk MichelleArk mentioned this issue Apr 20, 2023
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working model_versions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants