Skip to content

Commit

Permalink
Fix slicing of tuple arrays with null inputs (#4421)
Browse files Browse the repository at this point in the history
The issue here was kind of silly: NULL was being produced, as is
proper, but because the Index and Slice nodes in pgast weren't derived
from BaseExpr (since they weren't *really* exprs), _infer_nullability
didn't consider it when figuring out the nullability of the output
slice, which then didn't get checked for NULL and was output to the
client.
  • Loading branch information
msullivan committed Sep 23, 2022
1 parent 83816f8 commit 9e46ae9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions edb/pgsql/ast.py
Expand Up @@ -730,12 +730,14 @@ class NamedFuncArg(ImmutableBaseExpr):
val: BaseExpr


class Index(ImmutableBase):
# N.B: Index and Slice aren't *really* Exprs but we mark them as such
# so that nullability inference gets done on them.
class Index(ImmutableBaseExpr):
"""Array subscript."""
idx: BaseExpr


class Slice(ImmutableBase):
class Slice(ImmutableBaseExpr):
"""Array slice bounds."""
# Lower bound, if any
lidx: typing.Optional[BaseExpr]
Expand Down
8 changes: 8 additions & 0 deletions tests/test_edgeql_select.py
Expand Up @@ -5296,6 +5296,14 @@ async def test_edgeql_select_slice_04(self):
[[(2, 'bar')]],
)

await self.assert_query_result(
r'''
select [(1,'foo'), (2,'bar'), (3,'baz')][<optional int32>$0:];
''',
[],
variables=(None,),
)

async def test_edgeql_select_tuple_01(self):
await self.assert_query_result(
r"""
Expand Down

0 comments on commit 9e46ae9

Please sign in to comment.