Skip to content

Commit 9910952

Browse files
authored
Fix an interaction between aliases and optional globals with a default (#9109)
Optional globals with a default get turned into *two* parameters, one for the value and one for whether they were set. This is to distinguish between the cases of setting to `{}` and not setting anything. The "unused parameter" handling wasn't accounting for this so we would pass more arguments than the query expected in cases where a global got seen during compilation but didn't end up in the final query.
1 parent fc4ea5d commit 9910952

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

edb/pgsql/compiler/clauses.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,12 @@ def fini_toplevel(
547547
name=pg_types.pg_type_from_ir_typeref(param.ir_type)
548548
)
549549
)))
550+
if isinstance(param, irast.Global) and param.has_present_arg:
551+
targets.append(pgast.ResTarget(val=pgast.TypeCast(
552+
arg=pgast.ParamRef(number=pgparam.index + 1),
553+
type_name=pgast.TypeName(name=('bool',)),
554+
)))
555+
550556
if targets:
551557
stmt.append_cte(
552558
pgast.CommonTableExpr(

tests/test_edgeql_globals.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class TestEdgeQLGlobals(tb.QueryTestCase):
5454
create global CurUser := (
5555
select User filter .name = global cur_user);
5656
57+
create alias DumbAlias := {
58+
cur_user := global cur_user,
59+
cur_card := global cur_card,
60+
};
61+
5762
create function get_current_user() -> OPTIONAL User using (
5863
select User filter .name = global cur_user
5964
);
@@ -914,3 +919,12 @@ async def test_edgeql_globals_schema_types_04(self):
914919
''',
915920
[]
916921
)
922+
923+
async def test_edgeql_globals_unused_01(self):
924+
# Make sure it works when selecting something
925+
# that has "unused" optional globals with a default.
926+
# (There previously was a bug where we'd choke because
927+
# of confusion about the "present" argument.)
928+
await self.con.query('''
929+
select DumbAlias { cur_user }
930+
''')

0 commit comments

Comments
 (0)