Skip to content

Commit 6f58fe9

Browse files
Chore: Fix tests and adapt parser methods for tokens size (#5738)
Signed-off-by: Themis Valtinos <73662635+themisvaltinos@users.noreply.github.com>
1 parent 08c1375 commit 6f58fe9

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

sqlmesh/core/dialect.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,10 @@ def _parse_if(self: Parser) -> t.Optional[exp.Expr]:
566566
if last_token.token_type == TokenType.R_PAREN:
567567
self._tokens[-2].comments.extend(last_token.comments)
568568
self._tokens.pop()
569+
if hasattr(self, "_tokens_size"):
570+
# keep _tokens_size in sync sqlglot 30.0.3 caches len(_tokens)
571+
# _advance() tries to read tokens[index + 1] past the new end
572+
self._tokens_size -= 1
569573
else:
570574
self.raise_error("Expecting )")
571575

sqlmesh/utils/jinja.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ def extract(self, jinja: str, dialect: str = "") -> t.Dict[str, MacroInfo]:
7979
self.reset()
8080
self.sql = jinja
8181
self._tokens = Dialect.get_or_raise(dialect).tokenize(jinja)
82+
83+
# guard for older sqlglot versions (before 30.0.3)
84+
if hasattr(self, "_tokens_size"):
85+
# keep the cached length in sync
86+
self._tokens_size = len(self._tokens)
8287
self._index = -1
8388
self._advance()
8489

tests/dbt/cli/test_run.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import typing as t
22
import pytest
33
from pathlib import Path
4+
import shutil
45
from click.testing import Result
56
import time_machine
67
from sqlmesh_dbt.operations import create
@@ -71,6 +72,10 @@ def test_run_with_changes_and_full_refresh(
7172
if partial_parse_file.exists():
7273
partial_parse_file.unlink()
7374

75+
cache_dir = project_path / ".cache"
76+
if cache_dir.exists():
77+
shutil.rmtree(cache_dir)
78+
7479
# run with --full-refresh. this should:
7580
# - fully refresh model_a (pick up the new records from external_table)
7681
# - deploy the local change to model_b (introducing the 'changed' column)

0 commit comments

Comments
 (0)