Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: align diagnostics after multiline SQL placeholders (#11224)

Shahmir Varqhacafa3f213738
diff --git a/marimo/_sql/parse.py b/marimo/_sql/parse.py
index 5e22c5b4a7..34b7909d04 100644
--- a/marimo/_sql/parse.py
+++ b/marimo/_sql/parse.py
@@ -151,16 +151,18 @@ def _parse_sql_duckdb(
line_prefix = subquery[last_newline_idx + 1 :]
column_number = len(line_prefix.encode("utf-16-le")) // 2
- # Bracket indices refer to the original SQL, but the error position refers
- # to SQL with added quotes. Compare both in the latter coordinate system.
+ # Count quotes separately: a multiline placeholder can put only its closing
+ # quote on the error line.
error_line_start = last_newline_idx + 1
cumulative_offset = 0
preceding_offset = 0
for idx, offset in idx_to_offset_dict.items():
sanitized_idx = idx + preceding_offset
+ closing_quote_idx = query.index("}", sanitized_idx) + 1
preceding_offset += offset
- if error_line_start <= sanitized_idx < position:
- cumulative_offset += offset
+ for quote_idx in (sanitized_idx, closing_quote_idx):
+ if error_line_start <= quote_idx < position:
+ cumulative_offset += 1
column_number -= cumulative_offset
sql_parse_result = SqlParseResult(
diff --git a/tests/_sql/test_sql_parse.py b/tests/_sql/test_sql_parse.py
index 48ed163c66..e3ccd95fa8 100644
--- a/tests/_sql/test_sql_parse.py
+++ b/tests/_sql/test_sql_parse.py
@@ -458,6 +458,10 @@ id FRM users"""
"SELECT {a}, {b}, {c}, {d}, {e};\nSELECT {value} FRM users",
"SELECT 'é😀', {a},\n{id} FRM users",
"SELECT {a}, {b}, {c}, {d}, {e} FRM users, {other}",
+ "SELECT {a\n} FRM users",
+ "SELECT {a\n+ b} FRM users",
+ "SELECT {a\n}, {b} FRM users",
+ "SELECT {a\n+ 😀} FRM users",
],
)
def test_bracket_positions_after_replacements(self, query: str):