Skip to content

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

Description

@ntantri

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

# input
models:
  +endpoint_settings: &defaults
    owner: my-team
    lifecycle: production
    retentionCategory:
      category: internal
      subCategory: internal.benchmarking
# 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
# 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions