Skip to content

feat(models): render blueprint vars in columns dict#5845

Open
lafirm wants to merge 2 commits into
SQLMesh:mainfrom
lafirm:feat/column-name-blueprints-python
Open

feat(models): render blueprint vars in columns dict#5845
lafirm wants to merge 2 commits into
SQLMesh:mainfrom
lafirm:feat/column-name-blueprints-python

Conversation

@lafirm

@lafirm lafirm commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes issue #5767 - adds support for rendering Python model columns keys (column names) and values (column types) from blueprint/global variables. Previously, column names were not rendered.

Problem

Python model metadata rendering supported macro expansion for many fields, but columns had gaps:

  • Column names in columns={...} could not be parameterized (for example, @{col_name})
  • Column types parameterized via macros/blueprints needed to render correctly before model creation
  • Existing early validation expectations for plain string column types (no macro syntax) needed to remain intact

This made blueprint-driven Python models less flexible and caused dialect validation edge cases.

What Changed

  1. Added explicit rendering logic for the columns field so both:
    • column names are rendered (keys)
    • column types are rendered (values), including macro/blueprint expressions
  2. Updated Python model decorator behaviour to:
    • preserve columns in kwargs for later render-time handling
    • validate non-macro plain string column types early
    • defer macro-containing column type validation until after rendering
  3. Ensured rendered columns are used when constructing the Python model

Test Plan

  1. Added coverage for blueprint-based dynamic column names and types in Python models
  2. Added coverage for global-variable-based dynamic column names
  3. Kept/validated existing dialect behaviour around invalid non-macro column type parsing
  4. Included formatting-only updates from ruff in a few unrelated files (no behaviour changes)

Docs

Updated Python model blueprinting docs with an example showing blueprint variables used for:

  1. column names
  2. column types

Validation

Ran targeted tests successfully:

  1. python3 -m pytest tests/core/test_model.py::test_python_model_dialect -x -q
  2. python3 -m pytest tests/core/test_model.py::test_python_model_blueprint_column_names tests/core/test_model.py::test_python_model_variable_column_names -x -q
  3. python3 -m pytest tests/core/test_model.py -k "blueprint" -q
  4. python3 -m pytest tests/core/test_model.py::test_python_model_dialect tests/core/test_model.py -k "column" -q

Backward Compatibility

  1. Existing static columns definitions continue to work unchanged.
  2. Invalid plain string column types still fail early (same expectation as before).
  3. Macro/blueprint-driven columns now work as intended.

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

Reviewer Notes

  1. Core behaviour is in Python model metadata rendering and decorator preprocessing
  2. A few additional files were touched by ruff formatting only; they do not introduce functional changes

lafirm added 2 commits June 17, 2026 10:14
Signed-off-by: lafirm <136463254+lafirm@users.noreply.github.com>
Signed-off-by: lafirm <136463254+lafirm@users.noreply.github.com>
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