Skip to content

Defer get_columns_in_relation when no exposures match in exposure_schema_validity#1014

Merged
elazarlachkar merged 1 commit into
masterfrom
fix/exposure-schema-validity-defer-columns-lookup
May 26, 2026
Merged

Defer get_columns_in_relation when no exposures match in exposure_schema_validity#1014
elazarlachkar merged 1 commit into
masterfrom
fix/exposure-schema-validity-defer-columns-lookup

Conversation

@elazarlachkar
Copy link
Copy Markdown
Contributor

@elazarlachkar elazarlachkar commented May 26, 2026

Summary

  • Move adapter.get_columns_in_relation(model) inside the matching_exposures | length > 0 branch in exposure_schema_validity
  • When no exposures depend on the tested model/source, the test already returns no_results_query() and never needs column metadata

Context

Fusion BigQuery CI fails test_exposure_schema_validity_no_exposures because dbt-fusion commit 81458a3f switched BigQuery get_columns_in_relation to ADBC get_table_schema() without preserving dbt-core's missing-table → empty-list behavior. The integration test creates a source YAML but does not seed a physical table.

This change avoids the unnecessary warehouse call on the no-exposures path while preserving existing validation behavior when exposures do match.

Test plan

  • Fusion BigQuery CI: test_exposure_schema_validity_no_exposures passes
  • Existing test_exposure_schema_validity_* cases still pass on other warehouses
  • Models with real exposures in exposures.yml (customers, orders) still validate columns when exposures match

Made with Cursor

Summary by CodeRabbit

  • Chores
    • Optimized test execution by deferring unnecessary column metadata retrieval when no matching exposures are found, improving overall test performance.

Review Change Stack

…osures match.

Skip warehouse column introspection on the no-exposures path so dbt-fusion
BigQuery no longer errors on missing source tables after ADBC get_table_schema.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link
Copy Markdown
Contributor

👋 @elazarlachkar
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in the elementary repository.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

📝 Walkthrough

Walkthrough

The test_exposure_schema_validity macro now defers column metadata retrieval until after determining that matching exposures exist, eliminating unnecessary adapter calls when no exposures match the test criteria.

Changes

Deferred column metadata retrieval

Layer / File(s) Summary
Conditional column metadata retrieval
macros/edr/tests/test_exposure_schema_validity.sql
The columns variable initialization via adapter.get_columns_in_relation(model) is moved from early setup into the `matching_exposures

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A rabbit hops through the macro so bright,
Moving columns to run only right—
When exposures exist, not before they're found,
Efficiency blooms, with a logical bound. 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: deferring get_columns_in_relation until after confirming matching exposures exist, which is the core optimization in this changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/exposure-schema-validity-defer-columns-lookup

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
macros/edr/tests/test_exposure_schema_validity.sql (1)

29-30: 💤 Low value

Optional: Consider adding a brief inline comment.

The deferred column fetch is a targeted optimization that avoids an unnecessary warehouse call when no exposures match. A brief comment could help future maintainers understand the rationale.

📝 Suggested inline comment
 {%- set invalid_exposures = [] -%}
 {%- if matching_exposures | length > 0 -%}
+    {# Defer columns fetch until needed; avoids warehouse call when no exposures match #}
     {%- set columns = columns or adapter.get_columns_in_relation(model) -%}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@macros/edr/tests/test_exposure_schema_validity.sql` around lines 29 - 30, Add
a short inline comment explaining why columns are fetched only when
matching_exposures has items: next to the conditional using matching_exposures
and the set of columns (the line with "{%- if matching_exposures | length > 0
-%}" and "{%- set columns = columns or adapter.get_columns_in_relation(model)
-%}"), insert a one-line comment noting this is a deferred optimization to avoid
a warehouse call when there are no matching exposures so maintainers understand
the rationale.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@macros/edr/tests/test_exposure_schema_validity.sql`:
- Around line 29-30: Add a short inline comment explaining why columns are
fetched only when matching_exposures has items: next to the conditional using
matching_exposures and the set of columns (the line with "{%- if
matching_exposures | length > 0 -%}" and "{%- set columns = columns or
adapter.get_columns_in_relation(model) -%}"), insert a one-line comment noting
this is a deferred optimization to avoid a warehouse call when there are no
matching exposures so maintainers understand the rationale.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ef6d39bc-1716-4684-8090-9ab12a402a66

📥 Commits

Reviewing files that changed from the base of the PR and between 8eaaf37 and d490cda.

📒 Files selected for processing (1)
  • macros/edr/tests/test_exposure_schema_validity.sql

@linear
Copy link
Copy Markdown

linear Bot commented May 26, 2026

CORE-877

@elazarlachkar elazarlachkar merged commit 7ef3b24 into master May 26, 2026
29 of 31 checks passed
@elazarlachkar elazarlachkar deleted the fix/exposure-schema-validity-defer-columns-lookup branch May 26, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants