Repository: edgedb/edgedb

Issue:
can not delete Vampire: InternalServerError: column "dde51130-637a-11ec-81ea-854924cb81a5" does not exist
<!-- Please search existing issues to avoid creating duplicates. -->
- EdgeDB Version: EdgeDB 1.0-rc.3+147eb62 (repl 1.0.0-rc.4+eb50f45)
- OS Version: Ubuntu 20.04.3

Steps to Reproduce:

1. Download project https://drive.google.com/file/d/1lkK-0AJRg_0QONZnGHiojdMygdoWTGsY/view?usp=sharing
2. unpack project
3. go to project directory and init project `edgedb project init`
4. in edgedb shell insert a Vampire object `INSERT Vampire {name := 'Some Name'};`
5. try to delete Vampire `DELETE Vampire;`
at this moment I get this error:
`edgedb error: InternalServerError: column "dde51130-637a-11ec-81ea-854924cb81a5" does not exist
  Hint: This is most likely a bug in EdgeDB. Please consider opening an issue ticket at https://github.com/edgedb/edgedb/issues/new?template=bug_report.md
  Server traceback:
      edb.errors.InternalServerError: column "dde51130-637a-11ec-81ea-854924cb81a5" does not exist`
<!-- If the issue is about a query error, please also provide your schema -->

Current error is caused by one of migrations in the project. If I create migration from scratch for existing schema there are no problems with deleting Vampire.



Discussion:
I think the issue is going to be some busted trigger stuff.
Minimized test case:
```
create type Foo;
create type Bar { create link foo -> Foo; };
alter type Bar { drop link foo; };
insert Foo;
delete Foo;
```

Resolving patch:
diff --git a/edb/pgsql/delta.py b/edb/pgsql/delta.py
--- a/edb/pgsql/delta.py
+++ b/edb/pgsql/delta.py
@@ -4056,8 +4056,9 @@ def _delete_link(
             condition = dbops.TableExists(name=old_table_name)
             self.pgops.add(
                 dbops.DropTable(name=old_table_name, conditions=[condition]))
-            self.schedule_endpoint_delete_action_update(
-                link, orig_schema, schema, context)
+
+        self.schedule_endpoint_delete_action_update(
+            link, orig_schema, schema, context)
 
 
 class CreateLink(LinkMetaCommand, adapts=s_links.CreateLink):


Test patch:
diff --git a/tests/test_edgeql_ddl.py b/tests/test_edgeql_ddl.py
--- a/tests/test_edgeql_ddl.py
+++ b/tests/test_edgeql_ddl.py
@@ -12335,7 +12335,8 @@ async def test_edgeql_ddl_drop_parent_multi_link(self):
             CREATE TYPE D {
                 CREATE MULTI LINK multi_link -> C;
             };
-            CREATE TYPE E EXTENDING D
+            CREATE TYPE E EXTENDING D;
+            INSERT C;
         """)
 
         await self.con.execute(r"""
@@ -12344,9 +12345,14 @@ async def test_edgeql_ddl_drop_parent_multi_link(self):
             };
         """)
 
+        await self.con.execute(r"""
+            DELETE C;
+        """)
+
     async def test_edgeql_ddl_drop_multi_parent_multi_link(self):
         await self.con.execute(r"""
             CREATE TYPE C;
+            INSERT C;
             CREATE TYPE D {
                 CREATE MULTI LINK multi_link -> C;
             };
@@ -12362,6 +12368,19 @@ async def test_edgeql_ddl_drop_multi_parent_multi_link(self):
             };
         """)
 
+        await self.con.execute(r"""
+            DELETE C;
+        """)
+
+    async def test_edgeql_ddl_drop_incoming_link(self):
+        await self.con.execute(r"""
+            create type Foo;
+            create type Bar { create link foo -> Foo; };
+            alter type Bar { drop link foo; };
+            insert Foo;
+            delete Foo;
+        """)
+
 
 class TestConsecutiveMigrations(tb.DDLTestCase):
     TRANSACTION_ISOLATION = False