Skip to content

Commit

Permalink
Make Object.property in indexes detached
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 d337345
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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
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 d337345

Please sign in to comment.