From 2a065c147cbeb9274b99b5c4b5ddec3f3ca14881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Fri, 19 Jul 2024 19:07:05 +0200 Subject: [PATCH] Fix pg_get_serial_sequence in SQL adapter (#7581) --- edb/pgsql/resolver/static.py | 6 ++++++ tests/test_sql_query.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/edb/pgsql/resolver/static.py b/edb/pgsql/resolver/static.py index 9f059471ecc..706ca9c7e28 100644 --- a/edb/pgsql/resolver/static.py +++ b/edb/pgsql/resolver/static.py @@ -220,6 +220,10 @@ def eval_FuncCall( span=expr.span, ) + if fn_name == "pg_get_serial_sequence": + # we do not expose sequences, so any calls to this function returns NULL + return pgast.NullConstant() + if fn_name == "to_regclass": arg = require_a_string_literal(expr, fn_name, ctx) return to_regclass(arg, ctx=ctx) @@ -306,6 +310,8 @@ def cast_to_regclass(param: pgast.BaseExpr, ctx: Context) -> pgast.BaseExpr: """ expr = eval(param, ctx=ctx) + if isinstance(expr, pgast.NullConstant): + return pgast.NullConstant() if isinstance(expr, pgast.StringConstant): return to_regclass(expr.val, ctx=ctx) if isinstance(expr, pgast.NumericConstant): diff --git a/tests/test_sql_query.py b/tests/test_sql_query.py index 95cc0096b61..63615a41d33 100644 --- a/tests/test_sql_query.py +++ b/tests/test_sql_query.py @@ -919,6 +919,23 @@ async def test_sql_query_static_eval_04(self): ) self.assertEqual(res, [[11]]) + async def test_sql_query_static_eval_05(self): + # pg_get_serial_sequence always returns NULL, we don't expose sequences + + res = await self.squery_values( + ''' + SELECT + CAST( + CAST( + pg_catalog.pg_get_serial_sequence('a', 'b') + AS REGCLASS + ) + AS OID + ) + ''' + ) + self.assertEqual(res, [[None]]) + async def test_sql_query_be_state(self): con = await self.connect(database=self.con.dbname) try: