Skip to content

Commit

Permalink
Add a NULL test when compiling iterator expressions (#3012)
Browse files Browse the repository at this point in the history
Otherwise an iterator over a missing pointer could produce output
  • Loading branch information
msullivan committed Oct 7, 2021
1 parent f2c6687 commit e09d873
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions edb/pgsql/compiler/clauses.py
Expand Up @@ -26,6 +26,7 @@
from edb.pgsql import ast as pgast
from edb.pgsql import types as pg_types

from . import astutils
from . import context
from . import dispatch
from . import output
Expand Down Expand Up @@ -215,6 +216,17 @@ def compile_iterator_expr(
query, iterator_expr.path_id, aspect='value', ctx=ctx)
iterator_query = iterator_rvar.query

# If the iterator value is nullable, add a null test. This
# makes sure that we don't spuriously produce output when
# iterating over options pointers.
assert isinstance(iterator_query, pgast.SelectStmt)
iterator_var = pathctx.get_path_value_var(
iterator_query, path_id=iterator_expr.path_id, env=ctx.env)
if iterator_var.nullable:
iterator_query.where_clause = astutils.extend_binop(
iterator_query.where_clause,
pgast.NullTest(arg=iterator_var, negated=True))

# Regardless of result type, we use transient identity,
# for path identity of the iterator expression. This is
# necessary to maintain correct correlation for the state
Expand Down
17 changes: 17 additions & 0 deletions tests/test_edgeql_select.py
Expand Up @@ -5475,6 +5475,23 @@ async def test_edgeql_select_for_03(self):
sort=lambda x: x['number'],
)

async def test_edgeql_select_for_04(self):
await self.assert_query_result(
r'''
SELECT Issue {
asdf := (
FOR z IN {.due_date} UNION (1)
)
}
FILTER .name = 'Release EdgeDB';
''',
[
{
'asdf': None
}
],
)

async def test_edgeql_select_json_01(self):
await self.assert_query_result(
r'''
Expand Down

0 comments on commit e09d873

Please sign in to comment.