Skip to content

fix: make extend_sqlglot idempotent - #5936

Closed
sravankumarkunadi wants to merge 1 commit into
SQLMesh:mainfrom
sravankumarkunadi:fix/extend-sqlglot-idempotent
Closed

fix: make extend_sqlglot idempotent#5936
sravankumarkunadi wants to merge 1 commit into
SQLMesh:mainfrom
sravankumarkunadi:fix/extend-sqlglot-idempotent

Conversation

@sravankumarkunadi

Copy link
Copy Markdown
Contributor

Fixes #5908.

_override saved whatever was currently installed under _<name>, so calling extend_sqlglot() a second time saved the SQLMesh wrapper as "the original". After that _parse_types called itself and every CAST/type parse in the process raised RecursionError, with sqlglot's real method gone. It doesn't need a deliberate double call: extend_sqlglot() is the first line of sqlmesh/__init__.py, so if anything later in that import fails, the package is evicted while the patched Parser stays behind, and the next import sqlmesh triggers it.

_override now returns early if the wrapper is already installed, and UNWRAPPED_INTERVAL_VALUES gets the same membership guard TRANSFORMS and WITH_SEPARATED_COMMENTS already had (it was growing by two entries per call).

Added test_extend_sqlglot_is_idempotent, which fails on main with the recursion assertion and passes here.

Signed-off-by: sravankumarkunadi <sravankumarkunadi@users.noreply.github.com>
@sravankumarkunadi

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #5921, which has the same fix and is already approved.

@sravankumarkunadi
sravankumarkunadi deleted the fix/extend-sqlglot-idempotent branch August 4, 2026 16:14
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.

extend_sqlglot() is not idempotent — a second call makes Parser._parse_types recurse infinitely (RecursionError)

1 participant