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

[Feature] Custom test name not honoured in "config" blocks #9740

Open
2 tasks done
mkielar opened this issue Mar 8, 2024 · 4 comments
Open
2 tasks done

[Feature] Custom test name not honoured in "config" blocks #9740

mkielar opened this issue Mar 8, 2024 · 4 comments
Labels
enhancement New feature or request help_wanted Trickier changes, with a clear starting point, good for previous/experienced contributors

Comments

@mkielar
Copy link

mkielar commented Mar 8, 2024

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

According to https://docs.getdbt.com/reference/resource-properties/data-tests#custom-data-test-name, one can specify name attribute in test configuration, to override default naming scheme dbt uses to print test reports.

The name attribute works well when specified in models.yml, but doesn't work in {{ config() }} blocks inside .sql files (which is why I report this as a bug).

Expected Behavior

I'd expect consistent behaviour - the name attribute should be honoured in both cases.

Steps To Reproduce

I have two tests.

The first one is defined in models.yml like this:

columns:
  - name: node_id
      tests:
        - dbt_expectations.expect_column_values_to_be_unique:
          name: 'Expect "node_id" values to be unique.'

The second, is a custom, singular data test, in a file called assert_example.sql, which looks like this:

{{
  config(
    name = 'Example assertion with custom name',
    severity = 'error',
    error_if = '>0',
  )
}}

-- Please disregard the query, it's just an example that returns something to fail the test.
SELECT example_field
 FROM ref('example_model')

Then, when I run dbt test, I get this:

08:15:04  Failure in test Expect "node_id" values to be unique. (models/staging/[MASKED]/models.yml)
08:15:04    Got 11289 results, configured to fail if != 0
08:15:04
08:15:04    compiled Code at target/compiled/[MASKED]/models/staging/[MASKED]/models.yml/Expect "node_id" values to be unique..sql
08:15:04
08:15:04  Failure in test assert_example (models/staging/[MASKED]/tests/assert_example.sql)
08:15:04    Got 1 result, configured to fail if >0
08:15:04
08:15:04    compiled Code at target/compiled/[MASKED]/models/staging/[MASKED]/tests/assert_example.sql

As you can see:

  • in case of the test defined through models.yml, the name attribute is honoured.
  • in case of the singular data test in .sql file, configured via {{ config() }} block, the name attribute is not honoured.

Relevant log output

See: _"Steps to reproduce"_.

Environment

- OS: fedoraremix, v.38, via Windows Subsystem for Linux, v.1.
- Python: 3.11.7
- dbt: 1.7.9

Which database adapter are you using with dbt?

bigquery

Additional Context

No response

@mkielar mkielar added bug Something isn't working triage labels Mar 8, 2024
@mkielar
Copy link
Author

mkielar commented Mar 8, 2024

Here's the use-case for it:

We use dbt to populate databases of a web-application. There are specific moments where these are ran, and they populate data to initiate some business processes in the application. I plan on having several table-wide tests, to guarantee data consistency, before web-app processes are initiated, but these tests will most definitely not be generic - one, perhaps more dedicated tests per table. Thus, singular data tests.

Now, because the data may be inconsistent (I'm loading it from several source systems which may serve out-of-sync, or corrupted information), I'd like to run dbt test and get a report of failures and warnings to show to the users when the process fails. These messages should be human readable. Names such as dbt_expectations_expect_column_values_to_be_between_users_user_details_age__120__0 are hardly readable for someone who doesn't work with DBT, and definitely not suited to be shown in an otherwise pretty Web UI.

So I thought I could name the tests using the name attribute, and while it works for generic tests in models.yml, I cannot make it work for singular tests in /test folder.

As a workaround:

  • I can, of course, name the file Example assertion with custom name.sql instead of assert_example.sql, and that seems to do what I want, but requires me to have whitespace in filenames (which I'm not too keen of).
  • I also can refactor my dedicated tests into generic ones, and invoke them from models.yml. This has the advantage of having all tests specified in a single place. It's just bending the tool to my needs instead of using it properly...

@dbeatty10 dbeatty10 added enhancement New feature or request and removed bug Something isn't working labels Mar 9, 2024
@dbeatty10 dbeatty10 self-assigned this Mar 9, 2024
@dbeatty10 dbeatty10 changed the title [Bug] Custom test name not honoured in "config" blocks [Feature] Custom test name not honoured in "config" blocks Mar 9, 2024
@dbeatty10 dbeatty10 added the help_wanted Trickier changes, with a clear starting point, good for previous/experienced contributors label Mar 9, 2024
@dbeatty10
Copy link
Contributor

Thanks for describing your use case and what you ran into @mkielar !

The docs you referenced only applies to the tests property within models, which are generic data tests (rather than including singular data tests as well). So I'm going to re-label this as a feature request.

I buy it that you should be able to customize the name for singular data tests just like they can be customized for generic data tests.

Since we'd be unable to prioritize this ourselves any time soon, I'm going to mark this as "help wanted".

@onerishabh
Copy link

Hey @dbeatty10 ,
Is this something I can dip my toe in? Keen to contribute to dbt-core ☺️

@octo-youcef
Copy link

@dbeatty10 @mkielar I'm more than happy to throw my name in the hat for this (with a little guidance). Roughly this requirement has come up at my work so fixing at source seems smarter than whatever terrible ideas I had for tackling this locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help_wanted Trickier changes, with a clear starting point, good for previous/experienced contributors
Projects
None yet
Development

No branches or pull requests

4 participants