Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix: skip comments when detecting a quoted routine call site

mateo-berrib75609223d07
diff --git a/tests/code_coverage_tests/check_migrations_no_data_rewrites.py b/tests/code_coverage_tests/check_migrations_no_data_rewrites.py
index cab28c49432..eca9094ef93 100644
--- a/tests/code_coverage_tests/check_migrations_no_data_rewrites.py
+++ b/tests/code_coverage_tests/check_migrations_no_data_rewrites.py
@@ -267,8 +267,11 @@ def mask(
hold SQL: dollar-quoted bodies, and the single-quoted literals `EXECUTE` runs. Also locate
the double-quoted identifiers that open a call (`"backfill"(`), so a routine invoked through
one can be found by name even though the call is blanked here the way every other quoted run
- of text is. A double-quoted identifier that is not a call site, a column, table, index, or
- constraint name, is left out, so it never masquerades as a call to a like-named routine."""
+ of text is. Whether an identifier opens a call is read from the masked text rather than the
+ raw SQL, so a comment sitting between the name and its parenthesis, blanked to spaces here, is
+ skipped exactly as whitespace is. A double-quoted identifier that opens no call, a column,
+ table, index, or constraint name, is left out, so it never masquerades as a call to a
+ like-named routine."""
chunks: list[str] = []
bodies: list[tuple[int, int]] = []
literals: list[tuple[int, int]] = []
@@ -299,7 +302,7 @@ def mask(
if character == "'":
closed = sql[stop - 1 : stop] == character
literals.append((index + 1, max(index + 1, stop - 1 if closed else stop)))
- elif OPENS_A_CALL.match(sql, stop):
+ else:
identifiers.append((index, stop))
chunks.append(blank(sql[index:stop]))
index = stop
@@ -319,7 +322,9 @@ def mask(
chunks.append(character)
index += 1
- return "".join(chunks), tuple(bodies), tuple(literals), tuple(identifiers)
+ masked = "".join(chunks)
+ calls = tuple((start, end) for start, end in identifiers if OPENS_A_CALL.match(masked, end))
+ return masked, tuple(bodies), tuple(literals), calls
def skip_block_comment(sql: str, start: int) -> int:
diff --git a/tests/test_litellm/test_check_migrations_no_data_rewrites.py b/tests/test_litellm/test_check_migrations_no_data_rewrites.py
index 1652ba6b8c8..b111a486d5c 100644
--- a/tests/test_litellm/test_check_migrations_no_data_rewrites.py
+++ b/tests/test_litellm/test_check_migrations_no_data_rewrites.py
@@ -437,6 +437,18 @@ class TestStoredRoutines:
sql = self.DEFINITION + 'SELECT "backfill" ();\n'
assert _keywords(tmp_path, sql) == ("UPDATE",)
+ def test_a_quoted_call_with_a_block_comment_before_its_parenthesis_still_counts(self, tmp_path):
+ sql = self.DEFINITION + 'SELECT "backfill" /* reason */ ();\n'
+ assert _keywords(tmp_path, sql) == ("UPDATE",)
+
+ def test_a_quoted_call_with_a_line_comment_before_its_parenthesis_still_counts(self, tmp_path):
+ sql = self.DEFINITION + 'SELECT "backfill" -- run it\n();\n'
+ assert _keywords(tmp_path, sql) == ("UPDATE",)
+
+ def test_a_quoted_column_followed_by_a_comment_is_still_not_a_call(self, tmp_path):
+ sql = self.DEFINITION + 'ALTER TABLE "Foo" ADD COLUMN "backfill" /* note */ int;\n'
+ assert _keywords(tmp_path, sql) == ()
+
def test_a_trigger_wiring_the_function_up_counts_as_a_call(self, tmp_path):
sql = self.DEFINITION + 'CREATE TRIGGER t AFTER INSERT ON "Foo" EXECUTE FUNCTION backfill();\n'
assert _keywords(tmp_path, sql) == ("UPDATE",)