Skip to content

dbt: verify polymorphic_value_invariant covers all four value columns + value_kind (invariant 8) #60

Description

@countercheck

Source: codebase audit, 2026-06-11 (audit finding F6, Tier 2)
Severity: Low-Medium
Category: Invariant surface

Problem

CLAUDE.md invariant 8: "Exactly one of `{option_key, value_numeric, value_text, value_date}` per fact row. dbt test enforces; don't skip."

The existing `polymorphic_value_invariant` test enforces this at mart time. After M5.5 introduced `value_kind` (option / text / numeric / date) as the discriminator computed in `int_survey_questions`, the test may or may not be checking each value column against its `value_kind` — needs verification.

Suggested approach

  1. Read dbt/tests/singular/polymorphic_value_invariant.sql and confirm:
    • Counts non-nulls across all four columns (option_key, value_numeric, value_text, value_date) — must equal 1 per row.
    • Cross-checks against `value_kind` if present — e.g. `value_kind='numeric'` ⇒ value_numeric NOT NULL AND others NULL.
  2. If the current test only counts non-nulls (correct for invariant 8 but doesn't catch a value_kind/value-column mismatch), either extend it or add a sibling test `value_kind_value_column_alignment` that asserts the discriminator → column mapping.
  3. If the test already does both — close as "no change needed" with a note in the PR description.

Verification

```bash
cd dbt && dbt build
```

Should still PASS, with the extended (or unchanged) test catching synthetic violations.

Why this matters

A bug in `int_response_selections` SQL or a future API code path could populate two value slots; today only the next `dbt build` catches it. The check is cheap and the failure mode is silent without it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions