From 82fac253798a4bdccae2ebcca9aa14e3a7d0ac4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Thu, 5 Dec 2024 10:46:17 +0100 Subject: [PATCH] Show a better message for SET/RESET/SHOW over SQL native protocol (#8056) --- edb/pgsql/resolver/dispatch.py | 2 +- edb/server/compiler/compiler.py | 2 +- edb/server/compiler/sql.py | 12 ++++++++++++ edb/server/defines.py | 3 +++ edb/server/protocol/pg_ext.pyx | 7 ++++++- tests/test_sql_query.py | 29 +++++++++++++++++++++++++++++ 6 files changed, 52 insertions(+), 3 deletions(-) diff --git a/edb/pgsql/resolver/dispatch.py b/edb/pgsql/resolver/dispatch.py index d3ec583fcf5..f20ff6c0a80 100644 --- a/edb/pgsql/resolver/dispatch.py +++ b/edb/pgsql/resolver/dispatch.py @@ -108,7 +108,7 @@ def _raise_unsupported(expr: pgast.Base) -> typing.Never: # title case to spaces pretty_name = re.sub(r'(?= 0 else None, + P=str(exc.position + 1) if exc.position >= 0 else None, + ) elif isinstance(exc, errors.EdgeDBError): args = dict(hint=exc.hint, detail=exc.details) if exc.line >= 0: diff --git a/tests/test_sql_query.py b/tests/test_sql_query.py index 2eff2b60bd9..2501ff1a483 100644 --- a/tests/test_sql_query.py +++ b/tests/test_sql_query.py @@ -2720,3 +2720,32 @@ async def test_native_sql_query_15(self): 'SELECT title FROM "Content" ORDER BY title', [{'title': 'Forrest Gump'}] ) + + async def test_native_sql_query_16(self): + with self.assertRaisesRegex( + edgedb.UnsupportedFeatureError, + "not supported: VARIABLE SET", + _position=14, # this point to `1`, but hey, better than nothing + ): + await self.assert_sql_query_result( + 'SET my_var TO 1', + [] + ) + + with self.assertRaisesRegex( + edgedb.UnsupportedFeatureError, + "not supported: VARIABLE RESET", + ): + await self.assert_sql_query_result( + 'RESET my_var', + [] + ) + + with self.assertRaisesRegex( + edgedb.UnsupportedFeatureError, + "not supported: VARIABLE SHOW", + ): + await self.assert_sql_query_result( + 'SHOW my_var', + [] + )