Skip to content

support sql_header config for data tests#12545

Open
aahel wants to merge 2 commits intomainfrom
feat/sql-header-test-config
Open

support sql_header config for data tests#12545
aahel wants to merge 2 commits intomainfrom
feat/sql-header-test-config

Conversation

@aahel
Copy link
Contributor

@aahel aahel commented Feb 26, 2026

Resolves #9775

Problem

The sql_header config is not supported for data tests (singular and generic). When users configure sql_header — either via the set_sql_header macro in singular tests or via YAML config: in generic tests — the value is silently dropped during parsing because:

  1. TestConfig has no sql_header field, so any value set during parsing is discarded during serialization.
  2. TestBuilder.CONFIG_ARGS does not include sql_header, so generic tests don't recognize it as a config key from YAML and it gets treated as a test argument instead.

This prevents users from prepending SQL statements before test execution — a capability that already works for models.

Solution

Add sql_header as a recognized config field for data tests:

  • Add sql_header: Optional[str] = None to TestConfig dataclass and include it in the same_contents modifiers list for partial parsing support.
  • Add "sql_header" to TestBuilder.CONFIG_ARGS so generic tests accept sql_header in their YAML config block.

Note: A companion PR in dbt-adapters is needed to actually prepend the sql_header in the test and unit test materialization macros (test.sql and unit.sql). Without that change, the config value is correctly parsed and stored but not applied during execution.

Checklist

  • I have read the contributing guide and understand what's expected of me.
  • I have run this code in development, and it appears to resolve the stated issue.
  • This PR includes tests, or tests are not required or relevant for this PR.
  • This PR has no interface changes (e.g., macros, CLI, logs, JSON artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX.
  • This PR includes type annotations for new and modified functions.

@aahel aahel requested a review from a team as a code owner February 26, 2026 10:47
@cla-bot cla-bot bot added the cla:yes label Feb 26, 2026
@github-actions
Copy link
Contributor

Additional Artifact Review Required

Changes to artifact directory files requires at least 2 approvals from core team members.

@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.37%. Comparing base (019ebdc) to head (c3fb292).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12545      +/-   ##
==========================================
- Coverage   91.45%   91.37%   -0.09%     
==========================================
  Files         203      203              
  Lines       25471    25551      +80     
==========================================
+ Hits        23294    23346      +52     
- Misses       2177     2205      +28     
Flag Coverage Δ
integration 88.18% <100.00%> (-0.16%) ⬇️
unit 65.41% <100.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Unit Tests 65.41% <100.00%> (-0.07%) ⬇️
Integration Tests 88.18% <100.00%> (-0.16%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aahel aahel self-assigned this Feb 26, 2026
@aahel aahel added the artifact_minor_upgrade To bypass the CI check by confirming that the change is not breaking label Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

artifact_minor_upgrade To bypass the CI check by confirming that the change is not breaking cla:yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Make sql_header configuration available on tests

1 participant