dbt-labs / dbt-labs/dbt-codegen

Does not escape columns matching keywords

Open
#261 1 comment 0 reactions 0 assignees View on GitHub
bug Stale triage
Dominant language
Makefile
Stars
676
Forks
132
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug
When generating base models with table columns that are keywords, it does not escape them to the correct casing for the underlying source.

### Steps to reproduce
Had a snowflake source table with a column name "ORDER". When generating the base models using codegen.create_base_models it did not escape the column, resulting in the generated output failing. In addition, as the column name was all uppercase, it was necessary to change the casing.

### Expected results
If the underlying column was `ORDER` the name should be escape and match this case, i.e. not `order`, it should be `"ORDER"`.

### Actual results
Generates `order`.

### Screenshots and log output

### System information
**The contents of your `packages.yml` file:
packages:
- package: metaplane/dbt_expectations
version: [">=0.10.9", "<0.11.0"]
- package: dbt-labs/dbt_utils
version: 1.3.1
- package: dbt-labs/codegen
version: 0.13.1

**Which database are you using dbt with?**
- [ ] postgres
- [ ] redshift
- [ ] bigquery
- [x] snowflake
- [ ] other (specify: ____________)

**The output of `dbt --version`:**
```
Core:
- installed: 1.9.0
```

**The operating system you're using:** Linux

**The output of `python --version`: Python 3.11.2

### Additional context

### Are you interested in contributing the fix?

Contributor guide

Open the contributing guide

Research direction

Start with the codegen.create_base_models macro and reproduce the issue against a Snowflake table containing an ORDER column. Trace how column names are rendered and verify that the generated base model preserves the uppercase name and escapes it as "ORDER"; done means the generated output is valid for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.