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

UX improvements to model versions #7435

Merged
merged 12 commits into from
Apr 25, 2023
Merged

Conversation

jtcohen6
Copy link
Contributor

@jtcohen6 jtcohen6 commented Apr 22, 2023

resolves #7443

Naive implementations for some of the proposed improvements I mention here:

Overview of changes

  1. By default, land the latest_version of dim_customers in <db>.<schema>.dim_customers (no suffix). This is a behavior change to the built-in generate_alias_name, so if we're going to do it, we should do it before the final release. We are going to recommend accomplishing this with a post-hook in the meantime. We are still discussing if it makes sense to vendor that macro code within dbt-core.
  2. By default, allow defining the latest_version of dim_customers in a file named dim_customers.sql (no suffix). The convention of dim_customers_vX.sql would also be supported — so this isn't actually a behavior change.
  3. Info-level log if you have an unpinned ref to a model that has a newer-than-latest (i.e. prerelease) version defined: "Heads up, your unpinned ref will roll over to the new version as soon as it's the latest." (Should this be a warning? If you're not actually referencing a model slated for deprecation...)
11:47:08  3 of 3 START sql view model dbt_jcohen.another_model ........................... [RUN]
11:47:09  While compiling 'another_model':
Found an unpinned reference to versioned model 'my_model' in 'my_dbt_project'.
Resolving to latest version: my_model.v2
A prerelease version 3 is available. It has not yet been marked 'latest' by its maintainer.
When that happens, this reference will resolve to my_model.v3 instead.

  Try out v3: {{ ref('my_dbt_project', 'my_model', v='3') }}
  Pin to v2:  {{ ref('my_dbt_project', 'my_model', v='2') }}

(Bonus) Raise a nicer error if I've written a ref pinned to a specific version, and the model I'm referencing isn't actually versioned. This came up during training, when someone didn't correctly define the versions block on their model — but it wasn't clear if the error was in the model configuration, or in the downstream ref. This isn't a behavior change, and the codepath is slightly trickier, so I'll probably just kick it out of this PR. Update: Kicked out of scope.

Checklist

@cla-bot cla-bot bot added the cla:yes label Apr 22, 2023
@github-actions
Copy link
Contributor

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

@jtcohen6 jtcohen6 force-pushed the jerco/model-versions-ux-feedback branch from 886170e to cd8832d Compare April 24, 2023 11:54
@jtcohen6 jtcohen6 marked this pull request as ready for review April 24, 2023 11:54
@jtcohen6 jtcohen6 requested review from a team as code owners April 24, 2023 11:54
@jtcohen6
Copy link
Contributor Author

jtcohen6 commented Apr 24, 2023

Holding off on merging until the outcome of this slack thread, wherein we decide whether to vendor create_latest_version_view within dbt-core directly. I'm leaning toward yes; I'd want to add another test for this.

Update: Let's opt for, this will come in v1.6; in the meantime, a macro you can copy-paste-edit-post-hook.

for k, v in manifest.nodes.items()
if k.startswith(f"{node.unique_id[:-len(str(node.version))]}")
]
)
Copy link
Contributor

@MichelleArk MichelleArk Apr 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think this can be simplified to:

max_version: Union[str, float, None] = max(  # type: ignore
  [v.version for v in manifest.nodes.values() if v.name == node.name]
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is ... clearly better

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broader refactoring suggestion: using UnparsedVersion for the comparisons, similar to what we do in the graph selector method here

                max_version = max(
                    [
                        UnparsedVersion(v.version)
                        for v in manifest.nodes.values()
                        if v.name == node.name and v.version is not None
                    ]
                )
                assert node.latest_version
                if max_version > UnparsedVersion(node.latest_version):
                    fire_event(
                        UnpinnedRefNewVersionAvailable(
                            node_info=get_node_info(),
                            ref_node_name=node.name,
                            ref_node_package=node.package_name,
                            ref_node_version=str(node.version),
                            ref_max_version=str(max_version.v),
                        )
                    )

The TypeError issues in unit testing should be fixed by updating the MockNode constructor:

+++ b/test/unit/utils.py
@@ -350,6 +350,7 @@ def MockNode(package, name, resource_type=None, **kwargs):
         **kwargs,
     )
     node.name = name
+    node.is_versioned = resource_type is NodeType.Model and version is not None
     return node

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the risk of expanding the intended scope of a partial parsing test - I'm going to borrow your commit 84cc3ca and check that this message is being logged in the case of an unpinned ref to a latest-not-newest model

@MichelleArk
Copy link
Contributor

Looking at the logged message:

Try out v3: {{ ref('my_dbt_project', 'my_model', v='3') }}
Pin to v2:  {{ ref('my_dbt_project', 'my_model', v='3') }}

Should the second line be:

Pin to v2:  {{ ref('my_dbt_project', 'my_model', v='2') }}

@jtcohen6
Copy link
Contributor Author

Will rebase after #7439 is merged

@jtcohen6 jtcohen6 force-pushed the jerco/model-versions-ux-feedback branch from fca9243 to 0713e9d Compare April 25, 2023 17:14
@jtcohen6 jtcohen6 merged commit d53bb37 into main Apr 25, 2023
@jtcohen6 jtcohen6 deleted the jerco/model-versions-ux-feedback branch April 25, 2023 17:56
github-actions bot pushed a commit that referenced this pull request Apr 25, 2023
* Latest version should use un-suffixed alias

* Latest version can be in un-suffixed file

* FYI when unpinned ref to model with prerelease version

* [WIP] Nicer error if versioned ref to unversioned model

* Revert "Latest version should use un-suffixed alias"

This reverts commit 3616c52.

* Revert "[WIP] Nicer error if versioned ref to unversioned model"

This reverts commit c9ae4af.

* Define real event for UnpinnedRefNewVersionAvailable

* Update pp test for implicit unsuffixed defined_in

* Add changelog entry

* Fix unit test

* marky feedback

* Add test case for UnpinnedRefNewVersionAvailable event

(cherry picked from commit d53bb37)
jtcohen6 added a commit that referenced this pull request Apr 26, 2023
* Latest version should use un-suffixed alias

* Latest version can be in un-suffixed file

* FYI when unpinned ref to model with prerelease version

* [WIP] Nicer error if versioned ref to unversioned model

* Revert "Latest version should use un-suffixed alias"

This reverts commit 3616c52.

* Revert "[WIP] Nicer error if versioned ref to unversioned model"

This reverts commit c9ae4af.

* Define real event for UnpinnedRefNewVersionAvailable

* Update pp test for implicit unsuffixed defined_in

* Add changelog entry

* Fix unit test

* marky feedback

* Add test case for UnpinnedRefNewVersionAvailable event

(cherry picked from commit d53bb37)

Co-authored-by: Jeremy Cohen <[email protected]>
@aranke aranke mentioned this pull request May 9, 2023
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CT-2469] Quick UX improvements to model versions
3 participants