dbt-labs / dbt-labs/dbt

[v2 Bug] dbt lint ignores SQLFluff range directives "-- noqa: disable=<rule>" / "-- noqa: enable=<rule>" (inline "-- noqa: <rule>" works)

Open
#16,175 0 comments 0 reactions 0 assignees View on GitHub
triage
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 v2.x compared to the latest version of dbt 1.x?

- [x] I believe this is a new bug in dbt v2.x
- [x] I have searched the existing issues and could not find a duplicate

### Current Behavior

The `dbt lint` docs state that it "supports the full SQLFluff suppression syntax" (https://docs.getdbt.com/reference/commands/lint). In practice, the **range form** of SQLFluff's `noqa` directive is silently ignored:

- `-- noqa: disable=CP02` at the top of a file → violations are still reported
- `-- noqa: disable=all` → still reported
- `-- noqa: disable=CP02` … `-- noqa: enable=CP02` block → both the suppressed line *and* the line after `enable` are reported
- Position does not matter (line 1 vs. line 2 after a blank line behave the same)

The **inline** form (`... -- noqa: CP02` at the end of the offending line) works. So the parser handles single-line suppression but not the `disable=` / `enable=` range grammar defined in `sqlfluff/core/rules/noqa.py` ("Expected 'noqa: enable=[,...] | all' or 'noqa: disable=[,...] | all'").

`dbt lint` does accept a `-- noqa-file` comment, which suppresses everything in the file. However this is **not** SQLFluff syntax: SQLFluff reports it as a parse error (`PRS | Malformed 'noqa' section`) and then reports the violations anyway. So a project that shares one `.sqlfluff` between pre-commit (SQLFluff) and CI (`dbt lint`) cannot use it as a workaround.

### Expected Behavior

`-- noqa: disable=[,...] | all` should suppress the listed rules from that line to the end of file (or until a matching `-- noqa: enable=...`), exactly as SQLFluff does:

- `noqa_disable_rule.sql` → no violations
- `noqa_disable_all.sql` → no violations
- `noqa_disable_enable.sql` → only the line **after** `enable=` is reported

### Steps To Reproduce

1. Minimal project with `.sqlfluff`:

```ini
[sqlfluff]
dialect = bigquery
templater = jinja
rules = CP02

[sqlfluff:rules:capitalisation.identifiers]
extended_capitalisation_policy = lower
```

(`lower` is used so that the camelCase columns below are a deterministic violation in both linters.)

2. Models:

`models/noqa_disable_rule.sql`
```sql
-- noqa: disable=CP02
SELECT
src.metadataJson AS metadata_json,
src.createdAt AS created_at
FROM raw_deals AS src
```

`models/noqa_disable_all.sql` — same file with `-- noqa: disable=all`.

`models/noqa_disable_enable.sql`
```sql
SELECT
-- noqa: disable=CP02
src.metadataJson AS metadata_json,
-- noqa: enable=CP02
src.createdAt AS created_at
FROM raw_deals AS src
```

`models/noqa_inline.sql` (control — this one works)
```sql
SELECT
src.metadataJson AS metadata_json, -- noqa: CP02
src.createdAt AS created_at -- noqa: CP02
FROM raw_deals AS src
```

3. Run `dbt lint` and `sqlfluff lint models/` and compare.

### Relevant log output

```shell
# -- noqa: disable=CP02 (line 1)
$ dbt lint --select noqa_disable_rule
[error] [IdentifierCaseMismatch (dbt0167)]: Identifier case is expected to be Lower across the query, got Camel ('metadataJson') [CP02].
--> models/noqa_disable_rule.sql:3:7
[error] [IdentifierCaseMismatch (dbt0167)]: Identifier case is expected to be Lower across the query, got Camel ('createdAt') [CP02].
--> models/noqa_disable_rule.sql:4:7
Finished 'lint' with 1 warning and 2 errors for target 'dev'

$ sqlfluff lint models/noqa_disable_rule.sql
All Finished! # suppressed, as expected

# -- noqa: disable=all
$ dbt lint --select noqa_disable_all
[error] ... ('metadataJson') [CP02]. --> models/noqa_disable_all.sql:3:7
[error] ... ('createdAt') [CP02]. --> models/noqa_disable_all.sql:4:7

$ sqlfluff lint models/noqa_disable_all.sql
All Finished!

# disable / enable block
$ dbt lint --select noqa_disable_enable
[error] ... ('metadataJson') [CP02]. --> models/noqa_disable_enable.sql:3:7 # should be suppressed
[error] ... ('createdAt') [CP02]. --> models/noqa_disable_enable.sql:5:7 # correct

$ sqlfluff lint models/noqa_disable_enable.sql
L: 5 | P: 7 | CP02 | Unquoted identifiers must be lower case. # only line 5, correct

# inline form (control — works)
$ dbt lint --select noqa_inline
Finished 'lint' with 1 warning for target 'dev' # (warning = unrelated jinja-templater notice)

$ sqlfluff lint models/noqa_inline.sql
All Finished!

# -- noqa-file (dbt-only extension, not portable)
$ dbt lint --select noqa_file
Finished 'lint' with 1 warning for target 'dev' # suppressed

$ sqlfluff lint models/noqa_file.sql
L: 1 | P: 1 | PRS | Malformed 'noqa' section. Expected 'noqa: [,...]
L: 3 | P: 7 | CP02 | Unquoted identifiers must be lower case.
L: 4 | P: 7 | CP02 | Unquoted identifiers must be lower case.
```

Summary:

| directive | dbt lint | SQLFluff 4.2.2 | parity |
|---|---|---|---|
| inline `-- noqa: CP02` | suppressed | suppressed | OK |
| `-- noqa: disable=CP02` (line 1) | **ignored** | suppressed | **mismatch** |
| `-- noqa: disable=all` | **ignored** | suppressed | **mismatch** |
| `disable=CP02` … `enable=CP02` | **both ignored** | correct range | **mismatch** |
| `-- noqa: disable=CP02` (line 2) | **ignored** | suppressed | **mismatch** |
| `-- noqa-file` | suppressed | **PRS parse error** | dbt-only syntax |

### Environment

```markdown
- OS: macOS 15 (Darwin 25.6.0), Apple Silicon
- CPU: ARM
- dbt distribution and version: dbt-fusion 2.0.0-preview.209
- SQLFluff used for comparison: 4.2.2
```

### Which database adapter are you using?

- [x] bigquery

### Is this a discrepancy vs. dbt 1.x?

Yes. Projects on dbt 1.x lint with SQLFluff, where `-- noqa: disable=...` has worked for years and is the documented way to suppress a rule for a whole file or a block. The same files produce violations under `dbt lint` on Fusion.

### Additional Context

- Our project has 27 staging models whose upstream source columns are camelCase (cannot be renamed). Each carries `-- noqa: disable=CP02` on line 1 and is clean under SQLFluff / pre-commit. Under `dbt lint` in dbt platform CI they produce ~96 `IdentifierCaseMismatch` errors, which is what led us to find this.
- Companion issue: `extended_capitalisation_policy = snake` / `camel` silently falls back to `consistent` (filed separately: https://github.com/dbt-labs/dbt-core/issues/16174).
- If `-- noqa-file` is intended as a supported dbt extension, it would help to document that it is not SQLFluff-compatible, since SQLFluff treats it as a parse error.

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.