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

Behavior change cumulative type param #10909

Merged
merged 4 commits into from
Nov 5, 2024

Conversation

DevonFulcher
Copy link
Contributor

@DevonFulcher DevonFulcher commented Oct 23, 2024

[Edited after my last commit]

Resolves #10960
Linear issue: SL-2935
docs: dbt-labs/docs.getdbt.com#6393

Problem & Solution

The type params for cumulative metrics have moved, so a behavior change needs to be implemented to surface this for users. This is what the warning looks like:

15:36:22  [WARNING]: Cumulative fields `type_params.window` and
`type_params.grain_to_date` have been moved and will soon be deprecated. Please
nest those values under `type_params.cumulative_type_params.window` and
`type_params.cumulative_type_params.grain_to_date`. See documentation on
behavior changes:
https://docs.getdbt.com/reference/global-configs/behavior-changes.

Here is what the error looks like when the user flips the behavior flag:

21:39:18  Cumulative fields `type_params.window` and `type_params.grain_to_date` should be nested under `type_params.cumulative_type_params.window` and `type_params.cumulative_type_params.grain_to_date`. Invalid metrics: orders_last_7_days. See documentation on behavior changes: https://docs.getdbt.com/reference/global-configs/behavior-changes.

Testing:

  • I ran dbt parse in jaffle-sl-template and I saw the warning message due to this metric defined there:
    type: cumulative
    type_params:
      measure: order_count
      window: 7 days
  • I updated this metric and didn't see the deprecation warning:
    type: cumulative
    type_params:
      measure:
        name: order_count
      cumulative_type_params:
        window: 7 days
  • I changed the metric back to the deprecated version, added this to dbt_project.yaml, and saw the error message and that dbt parse failed:
flags:
  require_nested_cumulative_type_params: True

Checklist

  • I have read the contributing guide and understand what's expected of me.
  • I have run this code in development, and it appears to resolve the stated issue.
  • This PR includes tests, or tests are not required or relevant for this PR.
  • This PR has no interface changes (e.g., macros, CLI, logs, JSON artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX.
  • This PR includes type annotations for new and modified functions.

@cla-bot cla-bot bot added the cla:yes label Oct 23, 2024
Copy link

codecov bot commented Oct 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.06%. Comparing base (8a17a0d) to head (d6f6283).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10909      +/-   ##
==========================================
- Coverage   89.07%   89.06%   -0.01%     
==========================================
  Files         183      183              
  Lines       23550    23580      +30     
==========================================
+ Hits        20976    21002      +26     
- Misses       2574     2578       +4     
Flag Coverage Δ
integration 86.36% <92.30%> (-0.02%) ⬇️
unit 62.79% <100.00%> (+0.51%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Unit Tests 62.79% <100.00%> (+0.51%) ⬆️
Integration Tests 86.36% <92.30%> (-0.02%) ⬇️

@DevonFulcher DevonFulcher force-pushed the behavior_change_cumulative_type_param branch from c6ac260 to 6da0bc6 Compare October 23, 2024 15:55
@DevonFulcher DevonFulcher reopened this Oct 23, 2024
Base automatically changed from Behavior_change_for_mf_timespine_without_yaml_configuration to main October 31, 2024 15:40
@DevonFulcher DevonFulcher force-pushed the behavior_change_cumulative_type_param branch from 2071399 to 92b6954 Compare October 31, 2024 15:47
@DevonFulcher DevonFulcher force-pushed the behavior_change_cumulative_type_param branch from 113c63a to 02d1902 Compare October 31, 2024 15:49
@DevonFulcher DevonFulcher marked this pull request as ready for review October 31, 2024 15:55
@DevonFulcher DevonFulcher requested a review from a team as a code owner October 31, 2024 15:55
@github-actions github-actions bot added the community This PR is from a community member label Oct 31, 2024
Copy link
Contributor

@ChenyuLInx ChenyuLInx left a comment

Choose a reason for hiding this comment

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

This change looks good to me except for one behavior. Also thanks for enumerate the tests you did in the PR description!

  • I would expect when you set require_nested_cumulative_type_params, the warning from using unnested param would be an error. Since now user is required to set that param in nested fashion

@DevonFulcher
Copy link
Contributor Author

This change looks good to me except for one behavior. Also thanks for enumerate the tests you did in the PR description!

  • I would expect when you set require_nested_cumulative_type_params, the warning from using unnested param would be an error. Since now user is required to set that param in nested fashion

@ChenyuLInx So, this follows other behavior changes like here by using a warning message, not an error message. Since the legacy behavior is still supported, I think it makes sense to keep as a warning. The message is to notify to the user to upgrade their legacy yaml spec, not to indicate that there was a failure during invocation.

@ChenyuLInx
Copy link
Contributor

The case there is if you change the flag to true, the warning will be gone, but dbt will actually behave differently(change the macro overwrite order). The changing behavior part is an important piece of this flag.
I didn't quite follow will the behavior of the SL command change if the user flip the flag to true but has old definition. Happy to sync live really quick

@ChenyuLInx
Copy link
Contributor

We talked on Slack, and @DevonFulcher is going to change the behavior to failure if the schema is not adjusted but the flag is flipped to true.

),
message=f"Cumulative metric {m} fields `type_params.window` and `type_params.grain_to_date` should be nested under `type_params.cumulative_type_params.window` and `type_params.cumulative_type_params.grain_to_date`. See documentation on behavior changes: https://docs.getdbt.com/reference/global-configs/behavior-changes.",
)
for m in metrics_using_old_params
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we update this to be just one error that lists all the metrics with deprecated fields? We previously had complaints from customers about this because it was extremely noisy to have a warning for each metric.

Copy link
Contributor

@courtneyholcomb courtneyholcomb left a comment

Choose a reason for hiding this comment

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

One suggestion but otherwise LGTM! Thank you!

def code(self) -> str:
return "D019"

def message(self) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be easy to add the names of the outdated metrics in this message? Otherwise it might be hard for users to find.
But if that doesn't work with the behavior change objects easily, it probably isn't worth it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya, I don't think that is a straightforward change, given that it would change the interface. I think that could be an enhancement in the future.

@ChenyuLInx ChenyuLInx merged commit e26af57 into main Nov 5, 2024
60 checks passed
@ChenyuLInx ChenyuLInx deleted the behavior_change_cumulative_type_param branch November 5, 2024 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes community This PR is from a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Behavior change for updating cumulative type param fields
3 participants