fix(dialect): make extend_sqlglot idempotent - #5921
Open
Sanjays2402 wants to merge 1 commit into
Open
Conversation
_override saved whatever was currently installed under _<name>, so a second extend_sqlglot() call saved the override itself as the original. The wrapper then called itself and every subsequent type/CAST parse raised RecursionError, with sqlglot's original method lost. _override now returns early when the override is already installed. Adds tests/core/test_dialect.py::test_extend_sqlglot_is_idempotent, which fails with RecursionError without the fix. Signed-off-by: Sanjay Santhanam <51058514+Sanjays2402@users.noreply.github.com>
StuffbyYuki
approved these changes
Jul 26, 2026
StuffbyYuki
left a comment
Collaborator
There was a problem hiding this comment.
@Sanjays2402 Thanks for the PR! Here are a few things (not blockers):
- Also guard
generator.UNWRAPPED_INTERVAL_VALUES(still appends every call; TRANSFORMS / WITH_SEPARATED_COMMENTS already have membership guards — called out in #5908). - Optional assert that a second call doesn’t grow
UNWRAPPED_INTERVAL_VALUES(or that__parse_typesstill points at sqlglot’s original).
Merge ready once ci tests pass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5908
Description
_overridesaved whatever was currently installed under_<name>, so a secondextend_sqlglot()call saved the override itself as the "original". The wrapper then called itself and every subsequent type/CAST parse raisedRecursionError, with sqlglot's original method lost. This is reachable without calling it twice on purpose:extend_sqlglot()is the first statement ofsqlmesh/__init__.py, so if anything later in that import cascade raises, the package is evicted fromsys.moduleswhile the patched globals survive, and the retry re-applies the patch._overridenow returns early when the override is already installed.Test Plan
Added
tests/core/test_dialect.py::test_extend_sqlglot_is_idempotent, which fails withRecursionErrorwithout the fix and passes with it.tests/core/test_dialect.pyis green (160 passed).Checklist
make styleand fixed any issuesmake fast-test)git commit -s) per the DCO