dbt-labs / dbt-labs/dbt

[Bug] Incorrect macro argument validation

Open
#12,574 2 comments 1 reaction 0 assignees View on GitHub
engine:v1 type:bug
Dominant language
Rust
Stars
13.8k
Forks
2.6k
Avg merge
21h 31m
Merged PRs (30d)
56

Description

### Is this a new bug in dbt-core?

- [x] I believe this is a new bug in dbt-core
- [x] I have searched the existing issues, and I could not find an existing issue for this bug

### Current Behavior

@sambloom92 uncovered **two** distinct bugs after [`arguments` for macros](https://docs.getdbt.com/reference/resource-properties/arguments) was implemented in https://github.com/dbt-labs/dbt-core/issues/11274. The first is in https://github.com/dbt-labs/dbt-core/issues/11792 and the 2nd is described below.

As noted in https://github.com/dbt-labs/dbt-core/issues/11792#issuecomment-3029427509 and https://github.com/dbt-labs/dbt-core/issues/11792#issuecomment-3035082157, the 2nd time you run `dbt parse`, it won't report that the arguments in the YAML and the Jinja definition are mismatched, even when they are 😭:

> All you have to do to make it pass is run dbt parse more than once without editing the `schema.yml` or cleaning the target directory.

### Expected Behavior

It should still give this warning:
```
The number of arguments in the yaml for macro ... does not match the jinja definition.
```

### Steps To Reproduce

As originally included in https://github.com/dbt-labs/dbt-core/issues/11792#issuecomment-3985264494:

### Reprex bug 2

Create these files:

`dbt_project.yml`

```yaml
flags:
validate_macro_args: true
```

`macros/macro_extra_yaml_arg.sql`

```sql
{% macro macro_extra_yaml_arg(arg1, arg2) %}
select '{{ arg1 }}' as col1, '{{ arg2 }}' as col2
{% endmacro %}
```

`macros/schema.yml`

```yaml
macros:
- name: macro_extra_yaml_arg
description: A regular macro with an extra arg in YAML not in Jinja
arguments:
- name: arg1
- name: arg2
- name: bogus_arg
description: This arg does NOT exist in the Jinja macro
```

Run these commands:

```shell
dbt clean && dbt parse
```

or:

```shell
dbt parse --no-partial-parse
```

Get this output (which includes the correct warning ✅ ):

```
Running with dbt=1.11.6
Registered adapter: duckdb=1.10.1
Unable to do partial parsing because saved manifest not found. Starting full parse.
The number of arguments in the yaml for macro macro_extra_yaml_arg does not match the jinja definition.
```

Then run:

```shell
dbt parse
```

Get this output (warning just disappears 💥)
```
Running with dbt=1.11.6
Registered adapter: duckdb=1.10.1
```

### Relevant log output

```shell

```

### Environment

```markdown
- OS:
- Python:
- dbt:
```

### Which database adapter are you using with dbt?

_No response_

### Additional Context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.