Skip to content

Commit

Permalink
Fix ON TARGET DELETE ALLOW behavior when link optionality is changed (
Browse files Browse the repository at this point in the history
#8419)

Currently, if you change whether a link is required, the behavior of
`ON TARGET DELETE ALLOW` isn't updated, so it might either incorrectly
allow or disallow deleting the last link, depending.

Fixes #8417.
  • Loading branch information
msullivan committed Feb 28, 2025
1 parent 9578faf commit 93f9339
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions edb/pgsql/delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -5278,6 +5278,17 @@ def apply(
self._alter_pointer_optionality(
schema, orig_schema, context, fill_expr=self.fill_expr)

# If the link has an Allow on target delete action, we
# need to refresh the triggers, since required and
# optional behave differently. (Required does a
# check.)
if (
self.scls.get_on_target_delete(schema) ==
s_links.LinkTargetDeleteAction.Allow
):
self.schedule_endpoint_delete_action_update(
self.scls, orig_schema, schema, context)

return schema


Expand Down
40 changes: 40 additions & 0 deletions tests/test_edgeql_ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16259,6 +16259,46 @@ async def test_edgeql_ddl_link_policy_16(self):
[],
)

async def test_edgeql_ddl_link_policy_17(self):
# Make sure that ALLOW works when changing optionality
await self.con.execute(r"""
CREATE TYPE Tgt;
CREATE TYPE Src {
CREATE MULTI LINK tgt -> Tgt {
ON TARGET DELETE ALLOW;
}
};
""")

await self.con.execute(r"""
INSERT Src { tgt := (INSERT Tgt) };
""")

await self.con.execute(r"""
ALTER TYPE Src {
ALTER LINK tgt {
SET REQUIRED
}
};
""")

async with self.assertRaisesRegexTx(edgedb.MissingRequiredError, ''):
await self.con.execute("""
DELETE Tgt;
""")

await self.con.execute(r"""
ALTER TYPE Src {
ALTER LINK tgt {
SET OPTIONAL
}
};
""")

await self.con.execute("""
DELETE Tgt;
""")

async def test_edgeql_ddl_link_policy_implicit_01(self):
await self.con.execute("""
create type T;
Expand Down

0 comments on commit 93f9339

Please sign in to comment.