dbt-labs / dbt-labs/dbt

[Bug] removing jinja whitespace breaks unit test

Open
#11,999 2 comments 0 reactions 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

Stripping white space out of a ref with `{{- ref("table") }}` causes unit tests to fail.

### Expected Behavior

It shouldn't cause unit tests to fail.

### Steps To Reproduce

Create the following in `models/`:

```sql
-- add_input.sql
select 1 as a, 2 as b
```

```sql
-- add_strip.sql
select
a + b as c
from {{- ref("add_input") -}}
```

```sql
-- add_no_strip.sql
select
a + b as c
from {{ ref("add_input") -}}
```

```yaml
# add.yaml
unit_tests:

- name: does_no_strip_work
description: "Check no strip"
model: add_no_strip
given:
- input: ref('add_input')
rows:
- {a: 1, b: 2}
expect:
rows:
- {c: 3}

- name: does_strip_work
description: "Check strip"
model: add_strip
given:
- input: ref('add_input')
rows:
- {a: 1, b: 2}
expect:
rows:
- {c: 3}
```

### Relevant log output

```shell
Run `uv run dbt build --select +add_strip` to get

➜ uv run dbt build --select +add_strip
21:18:25 Running with dbt=1.10.11
21:18:25 Registered adapter: redshift=1.9.5
21:18:25 Found 37 models, 1 test, 646 macros, 6 unit tests
21:18:25
21:18:25 Concurrency: 1 threads (target='user')
21:18:25
21:18:30 1 of 3 START sql view model dev_nickmacro.add_input ............................ [RUN]
21:18:33 1 of 3 OK created sql view model dev_nickmacro.add_input ....................... [SUCCESS in 3.31s]
21:18:33 2 of 3 START unit_test add_strip::does_strip_work .............................. [RUN]
21:18:34 2 of 3 ERROR add_strip::does_strip_work ........................................ [ERROR in 1.39s]
21:18:34 3 of 3 SKIP relation dev_nickmacro.add_strip ................................... [SKIP]
21:18:35
21:18:35 Finished running 1 unit test, 2 view models in 0 hours 0 minutes and 9.90 seconds (9.90s).
21:18:35
21:18:35 Completed with 1 error, 0 partial successes, and 0 warnings:
21:18:35
21:18:35 Failure in unit_test does_strip_work (models/example/add.yaml)
21:18:35 Runtime Error in unit_test does_strip_work (models/example/add.yaml)
An error occurred during execution of unit test 'does_strip_work'. There may be an error in the unit test definition: check the data types.
Database Error
syntax error at or near "from__dbt__cte__add_input" in context "b as c
from__dbt__cte__add_input", at line 26, column 1
21:18:35
21:18:35 Done. PASS=1 WARN=0 ERROR=1 SKIP=1 NO-OP=0 TOTAL=3

Run `uv run dbt build --select +add_no_strip` to get

➜ uv run dbt build --select +add_no_strip
21:18:50 Running with dbt=1.10.11
21:18:50 Registered adapter: redshift=1.9.5
21:18:50 Found 37 models, 1 test, 646 macros, 6 unit tests
21:18:50
21:18:50 Concurrency: 1 threads (target='user')
21:18:50
21:18:55 1 of 3 START sql view model dev_nickmacro.add_input ............................ [RUN]
21:18:58 1 of 3 OK created sql view model dev_nickmacro.add_input ....................... [SUCCESS in 3.05s]
21:18:58 2 of 3 START unit_test add_no_strip::does_no_strip_work ........................ [RUN]
21:19:00 2 of 3 PASS add_no_strip::does_no_strip_work ................................... [PASS in 2.75s]
21:19:00 3 of 3 START sql view model dev_nickmacro.add_no_strip ......................... [RUN]
21:19:03 3 of 3 OK created sql view model dev_nickmacro.add_no_strip .................... [SUCCESS in 2.62s]
21:19:04
21:19:04 Finished running 1 unit test, 2 view models in 0 hours 0 minutes and 13.78 seconds (13.78s).
21:19:04
21:19:04 Completed successfully
21:19:04
21:19:04 Done. PASS=3 WARN=0 ERROR=0 SKIP=0 NO-OP=0 TOTAL=3
```

### Environment

```markdown
- OS: MacOS 15.6.1
- Python: 3.11.5
- dbt: 1.10.11
- dbt-redshift: 1.9.5
```

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

redshift

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