Skip to content

Commit

Permalink
Make Object.property in indexes detached (#5668)
Browse files Browse the repository at this point in the history
A followup for #5606 (comment)

This is techincally a breaking change, since any index definitions
that are using `Object.property` will now throw errors. I do think it is
quite minor and will probably not affect anyone, as this pattern is not documented
and treated as detached in all other SDL expressions apart from computeds.
  • Loading branch information
aljazerzen committed Jun 16, 2023
1 parent 4d24126 commit 2363ace
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion edb/schema/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,13 @@ def compile_expr_field(
singletons=frozenset([subject]),
apply_query_rewrites=False,
track_schema_ref_exprs=track_schema_ref_exprs,
detached=True,
),
)

# Check that the inferred cardinality is no more than 1
if expr.irast.cardinality.is_multi():
raise errors.ResultCardinalityMismatchError(
raise errors.SchemaDefinitionError(
f'possibly more than one element returned by '
f'the index expression where only singletons '
f'are allowed',
Expand Down
6 changes: 3 additions & 3 deletions tests/test_edgeql_ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12291,7 +12291,7 @@ async def test_edgeql_ddl_prop_alias(self):

async def test_edgeql_ddl_index_01(self):
with self.assertRaisesRegex(
edgedb.ResultCardinalityMismatchError,
edgedb.SchemaDefinitionError,
r"possibly more than one element returned by the index expression",
_line=4, _col=34
):
Expand All @@ -12304,7 +12304,7 @@ async def test_edgeql_ddl_index_01(self):

async def test_edgeql_ddl_index_02(self):
with self.assertRaisesRegex(
edgedb.ResultCardinalityMismatchError,
edgedb.SchemaDefinitionError,
r"possibly more than one element returned by the index expression",
_line=5, _col=34
):
Expand All @@ -12318,7 +12318,7 @@ async def test_edgeql_ddl_index_02(self):

async def test_edgeql_ddl_index_03(self):
with self.assertRaisesRegex(
edgedb.ResultCardinalityMismatchError,
edgedb.SchemaDefinitionError,
r"possibly more than one element returned by the index expression",
_line=5, _col=34
):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,18 @@ async def test_index_09(self):
}],
}],
)

async def test_index_10(self):
with self.assertRaisesRegex(
edgedb.SchemaDefinitionError,
r"possibly more than one element returned",
):
await self.con.execute(
r"""
create type Foo {
create property val -> str;
create index on (Foo.val);
};
"""
)

0 comments on commit 2363ace

Please sign in to comment.