Repository: edgedb/edgedb

Issue:
Error creating migration: <QualName __::...> is not a computable pointer
<!-- Please search existing issues to avoid creating duplicates. -->
- EdgeDB Version: `1.0-beta.2+dev.5519.ga407daf8b`

I only changed type name:
```diff
 module default {
-    type UserGuildSettings {
+    type AccentSettings {
         required property user_id -> snowflake;
         required property guild_id -> snowflake;
         property accents -> array<tuple<name: str, severity: int16>> {
             default := <array<tuple<name: str, severity: int16>>>[]
         };
 
         # https://github.com/edgedb/edgedb/issues/1939#issuecomment-789197413
         # constraint exclusive on ((.user_id, .guild_id));
         property exclusive_hack {
             using ((.user_id, .guild_id));
             constraint exclusive;
         };
     }
 
     scalar type snowflake extending int64;
 };
```

Traceback:
```python
$ edgedb -I potato_bot create-migration 
edgedb error: ERROR: InternalServerError: <QualName __::exclusive_hack> is not a computable pointer
  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:
      Traceback (most recent call last):
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/edgeql/compiler/setgen.py", line 1029, in computable_ptr_set
          comp_info = ctx.source_map[ptrcls]
      KeyError: <Property 3bbf08be-8194-11eb-ac52-33c7be8b6238 at 0x0x7f75459dc880>
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/server/compiler_pool/worker.py", line 312, in worker
          res = meth(*args)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/server/compiler_pool/worker.py", line 198, in compile_in_tx
          units, cstate = COMPILER.compile_in_tx(cstate, *args, **kwargs)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/server/compiler/compiler.py", line 2004, in compile_in_tx
          return self._compile(ctx=ctx, source=source), ctx.state
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/server/compiler/compiler.py", line 1545, in _compile
          return self._try_compile(ctx=ctx, source=original)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/server/compiler/compiler.py", line 1602, in _try_compile
          comp, capabilities = self._compile_dispatch_ql(ctx, stmt)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/server/compiler/compiler.py", line 1484, in _compile_dispatch_ql
          query = self._compile_ql_migration(ctx, ql)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/server/compiler/compiler.py", line 1008, in _compile_ql_migration
          proposed_ddl = s_ddl.statements_from_delta(
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/ddl.py", line 704, in statements_from_delta
          stmts = ddlast_from_delta(
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/ddl.py", line 685, in ddlast_from_delta
          schema = command.apply(schema, context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 3318, in apply
          schema = self._alter_innards(schema, context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 2987, in _alter_innards
          schema = op.apply(schema, context=context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 3318, in apply
          schema = self._alter_innards(schema, context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 2987, in _alter_innards
          schema = op.apply(schema, context=context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 3012, in apply
          schema = self._alter_finalize(schema, context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 2995, in _alter_finalize
          return self._finalize_affected_refs(schema, context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 2004, in _finalize_affected_refs
          schema = delta.apply(schema, context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 1006, in apply
          schema = op.apply(schema, context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 3318, in apply
          schema = self._alter_innards(schema, context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 2987, in _alter_innards
          schema = op.apply(schema, context=context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 3318, in apply
          schema = self._alter_innards(schema, context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 2987, in _alter_innards
          schema = op.apply(schema, context=context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 3317, in apply
          schema = self._alter_begin(schema, context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/inheriting.py", line 858, in _alter_begin
          schema = super()._alter_begin(schema, context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/inheriting.py", line 55, in _alter_begin
          schema = super()._alter_begin(schema, context)  # type: ignore
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 2977, in _alter_begin
          props = self.get_resolved_attributes(schema, context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 2435, in get_resolved_attributes
          result[attr] = self.get_resolved_attribute_value(
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 2381, in get_resolved_attribute_value
          value = self.resolve_attribute_value(
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/delta.py", line 2411, in resolve_attribute_value
          value = self.compile_expr_field(schema, context, field, value)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/constraints.py", line 488, in compile_expr_field
          return s_expr.Expression.compiled(
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/schema/expr.py", line 162, in compiled
          ir = qlcompiler.compile_ast_to_ir(
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/edgeql/compiler/__init__.py", line 177, in wrapper
          return func(*args, **kwargs)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/edgeql/compiler/__init__.py", line 223, in compile_ast_to_ir
          ctx = stmtctx_mod.init_context(schema=schema, options=options)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/edgeql/compiler/stmtctx.py", line 88, in init_context
          populate_anchors(options.anchors, ctx=subctx)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/edgeql/compiler/stmtctx.py", line 473, in populate_anchors
          ctx.anchors[name] = compile_anchor(name, val, ctx=ctx)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/edgeql/compiler/stmtctx.py", line 389, in compile_anchor
          path = setgen.extend_path(
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/edgeql/compiler/setgen.py", line 717, in extend_path
          target_set = computable_ptr_set(
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-beta2-dev5519/lib/python3.9/site-packages/edb/edgeql/compiler/setgen.py", line 1065, in computable_ptr_set
          raise errors.InternalServerError(
      edb.errors.InternalServerError: <QualName __::exclusive_hack> is not a computable pointer
```



Discussion:
`$ edgedb show-status` causes the same error, I don't know how long it did this, haven't used command before

Resolving patch:
diff --git a/edb/schema/delta.py b/edb/schema/delta.py
--- a/edb/schema/delta.py
+++ b/edb/schema/delta.py
@@ -293,7 +293,8 @@ def sort_by_cross_refs(
     for x in objs:
         graph[x] = topological.DepGraphEntry(
             item=x,
-            deps=set(schema.get_referrers(x)),
+            deps={ref for ref in schema.get_referrers(x)
+                  if not x.is_parent_ref(schema, ref)},
             extra=False,
         )
 
@@ -1105,7 +1106,7 @@ def __init__(
         self.backend_runtime_params = backend_runtime_params
         self.affected_finalization: Dict[
             Command,
-            List[Tuple[Command, Command, List[str]]],
+            List[Tuple[Command, ObjectCommand[so.Object], List[str]]],
         ] = collections.defaultdict(list)
         self.compat_ver = compat_ver
 
@@ -1997,7 +1998,18 @@ def _finalize_affected_refs(
         schema: s_schema.Schema,
         context: CommandContext,
     ) -> s_schema.Schema:
+
+        # There might be dependencies between the things we need to
+        # fix up (a computed property and a constraint on it, for
+        # example, requires us to fix up the computed property first),
+        # so sort by dependency order.
+        objs_to_cmds = {}
         for delta, cmd, refdesc in context.affected_finalization.get(self, []):
+            objs_to_cmds[cmd.scls] = delta, cmd, refdesc
+        objs = sort_by_cross_refs(schema, objs_to_cmds.keys())
+
+        for obj in reversed(objs):
+            delta, cmd, refdesc = objs_to_cmds[obj]
             try:
                 self._finalize_affected_refs_specialize(cmd, schema, context)
 


Test patch:
diff --git a/tests/test_schema.py b/tests/test_schema.py
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -4985,6 +4985,27 @@ def test_schema_migrations_equivalence_rename_refs_06(self):
             alias Alias3 := Remark { command := .remark ++ "!" };
         """])
 
+    def test_schema_migrations_equivalence_rename_refs_07(self):
+        self._assert_migration_equivalence([r"""
+            type Obj1 {
+                 required property id1 -> str;
+                 required property id2 -> str;
+                 property exclusive_hack {
+                     using ((.id1, .id2));
+                     constraint exclusive;
+                 };
+             }
+        """, r"""
+            type Obj2 {
+                 required property id1 -> str;
+                 required property id2 -> str;
+                 property exclusive_hack {
+                     using ((.id1, .id2));
+                     constraint exclusive;
+                 };
+             }
+        """])
+
     def test_schema_migrations_equivalence_rename_alias_01(self):
         self._assert_migration_equivalence([r"""
             type Note {