dbt-labs / dbt-labs/dbt-autofix

+prefixed custom config keys with dict values mangled in dbt_project.yml top-level

Open
#381 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
88
Forks
19
Avg merge
1d 1h
Merged PRs (30d)
13

Description

## Bug

`dbt-autofix` mangles `+`-prefixed custom config keys that have dict values when they appear at the top level of `models:` (or other node-type sections) in `dbt_project.yml`.

The root cause: `changeset_dbt_project_prefix_plus_for_config` doesn't check for `+` prefix in its `else` branch, it assumes any unrecognised key with a dict value is a project path and recurses into it. `rec_check_yaml_path` already handles this correctly at nested levels.

## Reproduction

```yaml
# input
models:
+endpoint_settings: &defaults
owner: my-team
lifecycle: production
retentionCategory:
category: internal
subCategory: internal.benchmarking
```

```yaml
# actual output — broken
models:
+endpoint_settings: &defaults
retentionCategory:
+category: "internal" # wrong: +prefix on plain data
+meta:
subCategory: internal.benchmarking
+meta:
owner: my-team
lifecycle: production
```

```yaml
# expected output
models:
+meta:
endpoint_settings: &defaults
owner: my-team
lifecycle: production
retentionCategory:
category: internal
subCategory: internal.benchmarking
```

`category` happens to be a valid dbt config field, so it gets `+` prefixed. Everything else gets shoved under `+meta` *inside* the anchor. This breaks YAML anchor inheritance for any project using `<<: *defaults` overrides.

## Fix

Add `elif k.startswith("+")` before the `else` branch in `changeset_dbt_project_prefix_plus_for_config`, move the key to `+meta` as a unit instead of recursing. This matches what `rec_check_yaml_path` already does for nested keys.

Tested on `0.20.2` and `0.20.4`.

I can raise a PR incoming.

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.