Skip to content

Conversation

@kalluripradeep
Copy link

Description

Fixes #6248

This PR adds summary output to the dbt source freshness command to display errors and warnings at the end of execution, similar to other dbt commands like dbt test and dbt run.

Previously, when running dbt source freshness, errors and warnings would get lost in the output with no summary. This made it difficult to quickly identify which sources had issues, especially when checking many sources.

Changes

  • Modified task_end_messages() in core/dbt/task/freshness.py to collect and display errors/warnings
  • Added summary header showing count of errors and warnings when they exist
  • Print each error/warning with source and table name at appropriate log levels
  • Added final statistics line showing PASS/WARN/ERROR/SKIP/TOTAL counts
  • Added Formatting import from dbt_common.events.types

Implementation Details

This implementation follows the maintainer's guidance to only modify freshness-related code and not touch other run result handling. The solution is self-contained within the freshness task.

Example Output

After this change, when running dbt source freshness, users will see:

Completed with 1 error and 1 warning:
Failure in source my_source.stale_table
Warning in source my_source.warn_table
Done. PASS=1 WARN=1 ERROR=1 SKIP=0 TOTAL=3

Testing

  • Verified code follows existing patterns from task/printer.py
  • Solution aligns with maintainer's proposed approach from issue discussion
  • Only modifies freshness task code as requested

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have signed the CLA
  • This PR includes code changes that address the issue
  • This PR follows the maintainer's guidance to only modify freshness-related code

…mmary output for dbt source freshness command Fixes dbt-labs#6248

Add summary output to `dbt source freshness` command showing errors and warnings with final statistics, similar to other dbt commands like `dbt test` and `dbt run`.

Changes:
- Modified task_end_messages() in freshness.py to collect and display errors/warnings
- Added summary header showing count of errors and warnings
- Print each error/warning with source and table name
- Added final statistics line (PASS/WARN/ERROR/SKIP/TOTAL)
- Added Formatting import from dbt_common.events.types

This implementation only modifies freshness-related code as requested by maintainers.
@kalluripradeep kalluripradeep requested a review from a team as a code owner November 28, 2025 20:46
@cla-bot
Copy link

cla-bot bot commented Nov 28, 2025

Thanks for your pull request, and welcome to our community! We require contributors to sign our Contributor License Agreement and we don't seem to have your signature on file. Check out this article for more information on why we have a CLA.

In order for us to review and merge your code, please submit the Individual Contributor License Agreement form attached above above. If you have questions about the CLA, or if you believe you've received this message in error, please reach out through a comment on this PR.

CLA has not been signed by users: @kalluripradeep

@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.

@github-actions github-actions bot added the community This PR is from a community member label Nov 28, 2025
@cla-bot cla-bot bot added the cla:yes label Nov 28, 2025
@pizofreude
Copy link

Great feature! Could you add unit tests for task_end_messages() covering scenarios like: all pass, some warnings, some errors, mixed results, and empty results?

Copy link

@pizofreude pizofreude left a comment

Choose a reason for hiding this comment

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

Thanks @kalluripradeep for this contribution. I've been waiting for this UX improvement. Ultimate blessing for BI/data teams monitoring source freshness.

What I liked:

  • Clean implementation following maintainer's guidance
  • Good use of existing event patterns (fire_event, Note, Formatting)
  • Proper pluralization in the summary message

Questions/Suggestions:

  • Could you clarify why RunStatus.Error was removed from the error handling?
  • Are there plans to add unit tests for the new task_end_messages() behavior?
  • Minor: Consider extracting the error/warning print logic into a helper to reduce duplication

Overall, LGTM!

):
print_run_result_error(result)

if result.status in (FreshnessStatus.Error, FreshnessStatus.RuntimeErr):

Choose a reason for hiding this comment

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

I noticed RunStatus.Error was previously handled but is now excluded. Is this intentional? Could there be scenarios where a freshness check returns RunStatus.Error?

Copy link
Author

Choose a reason for hiding this comment

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

I removed RunStatus.Error because freshness checks return FreshnessStatus (Error, RuntimeErr, Warn, Pass), not RunStatus. The freshness task has its own status enum separate from run/test tasks. I've verified this covers all freshness error scenarios.

EventLevel.INFO,
)

# Print each error

Choose a reason for hiding this comment

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

Minor suggestion: The error and warning printing logic is quite similar. Consider extracting a helper function like _print_result_message(result, level, prefix) to reduce duplication.

Copy link
Author

Choose a reason for hiding this comment

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

I'll extract a helper function _print_freshness_result() to reduce the duplication between error and warning printing.

# Print each error
for error in errors:
fire_event(Formatting(""))
if hasattr(error, 'node'):
Copy link

@pizofreude pizofreude Dec 7, 2025

Choose a reason for hiding this comment

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

The hasattr checks are good, but what happens if neither error.node nor error.source_name/error.table_name exist? Consider adding an else fallback or a comment explaining when each case occurs.

Copy link
Author

Choose a reason for hiding this comment

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

I'll add an else fallback. The error.node case handles standard freshness results, while source_name/table_name handle edge cases. I'll add a comment explaining this and a fallback for unexpected cases.

@kalluripradeep
Copy link
Author

Great feature! Could you add unit tests for task_end_messages() covering scenarios like: all pass, some warnings, some errors, mixed results, and empty results?

Absolutely! I'll add unit tests covering:

  • All pass scenario
  • Some warnings
  • Some errors
  • Mixed results (pass + warn + error)
  • Empty results

Working on this now.

@kalluripradeep
Copy link
Author

kalluripradeep commented Dec 7, 2025

Thanks @kalluripradeep for this contribution. I've been waiting for this UX improvement. Ultimate blessing for BI/data teams monitoring source freshness.

What I liked:

  • Clean implementation following maintainer's guidance
  • Good use of existing event patterns (fire_event, Note, Formatting)
  • Proper pluralization in the summary message

Questions/Suggestions:

  • Could you clarify why RunStatus.Error was removed from the error handling?
  • Are there plans to add unit tests for the new task_end_messages() behavior?
  • Minor: Consider extracting the error/warning print logic into a helper to reduce duplication

Overall, LGTM!

Thanks for the feedback @pizofreude! I've addressed all your suggestions:

  • Added unit tests covering all scenarios (all pass, some warnings, some errors, mixed results, empty results, and edge cases)

  • Extracted _print_freshness_result() helper function to reduce code duplication between error and warning printing

  • Added fallback handling in the helper for unexpected result structures with explanatory comments

All changes pushed and ready for review!

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.

[CT-1505] [Feature] Freshness checks should repeat errored tests at the end

2 participants