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: read through a schema qualifier when telling a table from a routine call

mateo-berri90a3101a458e
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 3ef290b40c9..adaabcae079 100644
--- a/tests/code_coverage_tests/check_migrations_no_data_rewrites.py
+++ b/tests/code_coverage_tests/check_migrations_no_data_rewrites.py
@@ -584,10 +584,16 @@ def names_a_relation(before: str) -> bool:
precede a call. `ON` is the ambiguous one, since it introduces the table of a `CREATE INDEX`
but also a join condition that may itself be a call, so it counts only inside a statement
that creates an index, leaving `JOIN ... ON f()` and an index predicate's `WHERE f()` as
- calls."""
+ calls. A bare schema qualifier is read through: `INSERT INTO public."Foo"` parks the table's
+ introducing word a hop back behind `public.`, so a dot touching the word before the name means
+ that word is the qualifier and the one before it decides. A quoted schema blanks to spaces and
+ leaves the introducing word already adjacent, so only a dot with no space counts, and a genuine
+ `SELECT public."f"()` still reaches its `SELECT` and reads as a call."""
word = PRECEDING_WORD.search(before)
if word is None:
return False
+ if before[word.end(1) : word.end(1) + 1] == ".":
+ return names_a_relation(before[: word.start(1)])
keyword = word.group(1).upper()
if keyword in INTRODUCES_A_RELATION:
return True
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 f3b35fd3448..00cdfc2343c 100644
--- a/tests/test_litellm/test_check_migrations_no_data_rewrites.py
+++ b/tests/test_litellm/test_check_migrations_no_data_rewrites.py
@@ -493,6 +493,18 @@ class TestStoredRoutines:
sql = self.DEFINITION + 'CREATE INDEX ON "Foo" ("a");\nSELECT 1 FROM "Bar" b JOIN "Baz" z ON "backfill"();\n'
assert _keywords(tmp_path, sql) == ("UPDATE",)
+ def test_an_insert_into_a_schema_qualified_like_named_table_is_not_a_call(self, tmp_path):
+ sql = self.DEFINITION + 'INSERT INTO public."backfill" ("id") VALUES (1);\n'
+ assert _keywords(tmp_path, sql) == ()
+
+ def test_a_schema_qualified_index_on_a_like_named_table_is_not_a_call(self, tmp_path):
+ sql = self.DEFINITION + 'CREATE INDEX ON public."backfill" ("id");\n'
+ assert _keywords(tmp_path, sql) == ()
+
+ def test_a_schema_qualified_quoted_call_still_counts(self, tmp_path):
+ sql = self.DEFINITION + 'SELECT public."backfill"();\n'
+ assert _keywords(tmp_path, sql) == ("UPDATE",)
+
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",)