edgedb / edgedb

A graph-relational database with declarative schema, built-in migration system, and a next-generation query language
https://edgedb.com
Apache License 2.0
13.1k stars 402 forks source link

Error while removing an object type which is having cyclic link #6478

Open raj-s-gouda opened 1 year ago

raj-s-gouda commented 1 year ago

I had an object type with cyclic link. When I try to apply migration (by removing this object type) I am getting following error

edgedb error: InternalServerError: CycleError: dependency cycle between ('alter', 'default::__|repName@default|J_User') and ('rename', 'default::J_User')
  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-4/lib/python3.11/site-packages/edb/server/compiler_pool/worker.py", line 203, in compile_in_tx
          units, cstate = COMPILER.compile_in_tx(cstate, *args, **kwargs)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/server/compiler/compiler.py", line 938, in compile_in_tx
          return compile(ctx=ctx, source=source), ctx.state
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/server/compiler/compiler.py", line 2305, in compile
          return _try_compile(ctx=ctx, source=original)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/server/compiler/compiler.py", line 2369, in _try_compile
          comp, capabilities = _compile_dispatch_ql(
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/server/compiler/compiler.py", line 2214, in _compile_dispatch_ql
          query = ddl.compile_dispatch_ql_migration(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/server/compiler/ddl.py", line 381, in compile_dispatch_ql_migration
          return _populate_migration(ctx, ql)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/server/compiler/ddl.py", line 492, in _populate_migration
          diff = s_ddl.delta_schemas(
                 ^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/schema/ddl.py", line 375, in delta_schemas
          objects = s_ordering.linearize_delta(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/schema/ordering.py", line 113, in linearize_delta
          sortedlist = [i[1] for i in topological.sort_ex(depgraph)]
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/common/topological.py", line 187, in sort_ex
          visit(key)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/common/topological.py", line 170, in visit
          visit(n, weak_link=weak_link)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/common/topological.py", line 170, in visit
          visit(n, weak_link=weak_link)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/common/topological.py", line 170, in visit
          visit(n, weak_link=weak_link)
        [Previous line repeated 1 more time]
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/common/topological.py", line 149, in visit
          raise CycleError(
      edb.common.topological.CycleError: dependency cycle between ('alter', 'default::__|repName@default|J_User') and ('rename', 'default::J_User')

Steps to Reproduce:

  1. Create Object Types having cyclic links
  2. Try to delete those by discarding them in new migration
aljazerzen commented 1 year ago

I'll need a bit more details. What's your starting schema? What are you trying to migrate to? Which migration workflow (commands) are you using?

We do handle case that you describe correctly, so the problem is probably in details.

For example, if I start with:

module default {
    type User {
        link biography: Post;
    };

    type Post {
        link author: User;
    }
};

... and try to migrate to:

module default {
    type User;
};

... migration is correctly generated:

CREATE MIGRATION m1uvdp7jybnsblq7idrumiejkllzcxcew2wbbt4v7ko56pdh3ei2nq
    ONTO m14nxctq4nhyvbel7klsb3oiwa7c25qxfko7mt6ruxbgtv76n3yhrq
{
  ALTER TYPE default::Post {
      DROP LINK author;
  };
  ALTER TYPE default::User {
      DROP LINK biography;
  };
  DROP TYPE default::Post;
};