Skip to content

feat: add automatic model query context - #6174

Draft
mday-io wants to merge 4 commits into
SQLMesh:mainfrom
mday-io:feat/automatic-query-execution-context
Draft

mday-io wants to merge 4 commits into
SQLMesh:mainfrom
mday-io:feat/automatic-query-execution-context

Conversation

@mday-io

@mday-io mday-io commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR depends on #6173. The branch includes the provider commit until #6173 merges.
This comparison
shows only the automatic-context changes.

Why

The provider in #6173 requires application code to connect warehouse statements
to model evaluations. A project configured through YAML needs SQLMesh to supply
that context automatically.

How

Use SQLMesh's native execution-observation hooks to create a context for each
model batch when a supported warehouse adapter has query_execution_context
enabled and no custom provider. Nested audits reuse the batch's operation ID.
Expose the same immutable context to observer callbacks. Restore the worker's
previous context after completion or cancellation.

Forward each event to a configured console observer once. If no observer is
configured, automatic context still works. observer_scope(None) disables the
built-in observer. SQL issued inside observer callbacks does not use automatic
model context. Custom providers remain authoritative, including when they return
None.

The built-in observer covers model batches and nested audits during
Context.apply() and built-in scheduler runs. It does not add model context to
standalone operations or promise a detailed role for each SQL statement.

Test Plan

  • 71 observer, transport, and native integration checks passed, including
    audit-only context and nested non-model or malformed-model context clearing.
  • All 15 CLI init and DLT tests passed.
  • make style passed.
  • make fast-test passed all six phases. 2,998 passed and 13 skipped.
  • make doc-test passed. 29 passed.
  • A native DuckDB check exercised Context.plan(), Context.apply(), and
    Context.run() in provider, automatic observer, and default console modes.
    IDs matched across six batches and audits. Observer IDs matched. Snapshot and
    interval metadata matched. Hashes and rows were unchanged, and default state
    SQL had no context.
  • The runnable provider example and isolated automatic-disablement mutation check
    passed.
  • Documentation links, navigation, and snippet checks passed. The strict MkDocs
    build was unavailable because MkDocs is not installed locally.

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

Signed-off-by: mday-io <mdaytn@gmail.com>
@coderabbitai

coderabbitai Bot commented Oct 31, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Signed-off-by: mday-io <mdaytn@gmail.com>
Signed-off-by: mday-io <mdaytn@gmail.com>
@mday-io
mday-io force-pushed the feat/automatic-query-execution-context branch from 6889176 to b57bc31 Compare October 31, 2026 23:30
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.

1 participant