Skip to content

refactor: expose macro evaluator in renderer #4729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

benfdking
Copy link
Contributor

@benfdking benfdking commented Jun 12, 2025

See #4605 for context

@benfdking benfdking requested a review from Copilot June 12, 2025 10:53
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Exposes the internal MacroEvaluator instance from the renderer so it can be accessed after rendering.

  • Initializes and caches _macro_evaluator in the renderer constructor.
  • Adds a read-only macro_evaluator property to return the last evaluated instance.
  • Assigns the macro_evaluator during table resolution in _resolve_table.
Comments suppressed due to low confidence (3)

sqlmesh/core/renderer.py:76

  • [nitpick] Consider expanding this docstring to clarify when this property is populated and what it returns if render hasn’t been called, to avoid confusion when consumers access it.
        """Returns the cached macro evaluator from the last render operation."""

sqlmesh/core/renderer.py:75

  • Add a unit test that runs through the rendering process and asserts that macro_evaluator returns a valid MacroEvaluator instance, ensuring this new property is covered by tests.
    def macro_evaluator(self) -> t.Optional[MacroEvaluator]:

sqlmesh/core/renderer.py:72

  • [nitpick] Consider resetting self._macro_evaluator at the start of each public render invocation (in addition to __init__) to prevent carrying over a stale evaluator when the same renderer instance is reused.
        self._macro_evaluator: t.Optional[MacroEvaluator] = None

@property
def macro_evaluator(self) -> t.Optional[MacroEvaluator]:
"""Returns the cached macro evaluator from the last render operation."""
return self._macro_evaluator
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't feel like a robust way of doing this. Can we instead have a method that constructs the MacroEvaluator instance? And then call it externally AND in _render?

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